I’ve recently tried to use MirroredStrategy for training. The relevant code is: dataset print is: which is in the correct dimension, but I get the following error: which is odd, as the documentation says that the strategy will halve the first dimension not the second, it should split the dataset for 2, …
How to do explode and keep a fair proportion of number value for each new row Pandas
I have this dataframe: I would like to use explode function for column “A” and then to keep right and fair proportion for each exploded row in case with column “B” . So the result should look like this: Would this be possible with the explode function? I would manage to come to this re…
Is it possible to view/print to console the idle queue in tkinter?
In reference to In tkinter GUI what are pending events and idle callbacks? question, which asks what are pending events and idle callbacks in tkinter, I was wondering if there is a way to print the event/idle queue to console or a tracelog. The only potential solution I could come up with is the code below, b…
Disable metacharacters in regular expressions
Perl has Q and E operators in its regular expression toolkit: Does such a facility exist in Python? I am aware of the in operator to do literal string comparison, but my usecase is that I’m using the lineinfile Ansible module which relies on Python’s regular expression library. I’d like some…
Example of passing a list of strings from Python to C++ function with Cython
I’m going in circles trying to figure out a fairly basic question in Cython. On the Python side, I have a list of variable-length strings. I need to pass these to a C++ function that will process this list and return some calculations (a vector of floats of same length as the input, if that matters). I …
How to show data by day in a Plotly chart
I have a dataframe with the number of people vaccinated per day and I’m trying to put this data in a daily bar chart of Plotly, but it aggregates the data every about 13 days. I don’t want the aggregated view this way, I need it to show the bars per day. Below is a part of the dataframe and
DRF Serializer – Accept field but don’t use it in `create` or `update`
I have a model Message that has a FileField. My API accepts files in Base64 encoding so they can be sent alongside other data. To know a filename and an extension, there is one more field attachment_filename in the serializer that is not a model field. It is used inside Base64Field. I want to be able to valid…
Add list as list element Python weird behaviour
I am trying to store the file indexes from a directory in a list variable using Python. This list will be used for a recursive function that will change the content of files, but the list is storing incorrect values. My directory has more than 5k files with the format: ccc-ppp.htm where ccc is the chapter num…
How to multiply specific rows/columns of matrices with each other in python?
I have to input matrices of shape I want to multiply each row (each n of size 3) with its correspondence of the other matrix, such that i get a (3,3) matrix for each row. When im trying to just use e.g. m1[0]@m2.T[0] the operation doesnt work, as m[0] delivers a (3,) list instead of a (3,1) matrix, on which
django db with ssh tunnel
Is there a python native way to connect django to a database through an ssh tunnel? I have seen people using ssh port forwarding in the host machine but I would prefer a solution that can be easily containerized. Answer It is pretty seamless. Requirements: The sshtunnel package https://github.com/pahaz/sshtun…