I have a numpy array of shape (30, 100, 28, 28) - 30 batches of 100 instances of 28x28. I would like to split this 4d numpy array into a list of length 30. In this list every element would be a numpy array of shape (100, 28, 28). How can I do that?
1 Answer
First, you can already consider it as a list, without converting it at all, you can iterate through it or do everything you can do with a list.
But if you really want a list, all you have to do is to pass it in the list constructor :
>>> m = np.zeros((30,100,28,28))
>>> m.shape
(30,100,28,28)
>>> l = list(m)
>>> type(l[0])
<class 'numpy.ndarray'>
>>> l[0].shape
(100, 28, 28)
>>> len(l)
30
l is your splitted list
list(my_numpy_array)