I have a list of 2d numpy arrays. As a test, consider the following list:
lst = [np.arange(10).reshape(5,2)]*10
Now I can get at a particular data element by:
lst[k][j,i]
I would like to convert this to a numpy array so that I can index it:
array[k,j,i]
i.e., the shape should be (10, 5, 2).
This seems to work, but seems completely unnecessary:
z = np.empty((10,5,2))
for i,x in enumerate(z):
x[:,:] = lst[i]
These don’t work:
np.hstack(lst)
np.vstack(lst)
np.dstack(lst) #this is closest, but gives wrong shape (5, 2, 10)
I suppose I could pair a np.dstack with a np.rollaxis, but again, that doesn’t seem quite right …
Is there a good way to do this with numpy?
I’ve looked at this very related post, but I can’t quite seem to work it out.
This should work simply by calling the array constructor, i.e.
np.array(lst).