Skip to content

Tag: python

numpy.reshape breaks when dealing with a view of a big size

I have an initial NumPy array of size (512,512,100) of type np.float64 and then I use view_as_windows function to get an array of size (499,499,100,64,64). This function returns a view that consumes much less memory than an actual NumPy array. I want to reshape the view to (499*499*100,64,64). Using the regul…

how to use python varname to get var names inside loops

I’m using the fantastic varname python package https://pypi.org/project/varname/ to print python var names from inside the code: but when I try to use it in a loop: I do not get to print a, b, c, … How could I get something like this ?: Answer You can put the for loop into a function, and then use…

Execute f-string in function

I have a and want to replace all tokens starting with with a new token I wrote a function: If I execute the lines separately it works. But the function itself doesn’t work. I’d expect How can I “exec” f-string in a function? Answer You are overcomplicating this. Simply reassign x: But …