I have a list t with a square number of elements, e.g. 16, 25, 400.
Now want to create a numpy array a full of zeros with the same size but in a square shape, e.g. 4x4, 5x5, 20x20.
I found a solution:
a = np.zeros(2 * (int(np.sqrt(len(t))),))
or
a = np.zeros(len(t)).reshape(int(np.sqrt(len(t))), int(np.sqrt(len(t))))
It is working, but it is very ugly and I am sure there must be a better way to do this.
Something like a = np.zeros(t, 2).
Any idea for that?
Thank you! :)
square_shape(length)function, and usenp.zeros(square_shape(len(l)))