0

Let Y be a list of 100 ndarrays, such that Y[i] is an ndarray of an image, its shape is 160x320x3.

I want X no be an ndarrays that contains all the images, I do as follows:

x = [ y[i] for i in range(0,10) ]

But it produces a list of of 100 160X320X3 ndarrays. How can I modify it to get an ndarray of shape 100x160x320x3 ?

0

1 Answer 1

2

Calling np.array on Y (i.e np.array(Y)) should turn the list of ndarrays into one ndarray, with the size of the first axis corresponding to the length of the list.

Demo:

>>> x = np.array([[1,2], [3,4]])
>>> c = [x,x] # list of 2x2 arrays
>>> c
[array([[1, 2],
       [3, 4]]), 
array([[1, 2],
       [3, 4]])]
>>> np.array(c) # 2x2x2 array
array([[[1, 2],
        [3, 4]],

       [[1, 2],
        [3, 4]]])

Just call np.array on Y, or x if you only want a slice of Y.

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.