0

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?

2

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.