0

I have a numpy array that is a 3d array. It is supposed to be shape (1000,100, 3), but the shape of it at first dimension is (1000,) and of each entry inside, the shape is (100, 3). How can I reshape it such that I have (1000,100, 3) for the original array?

0

1 Answer 1

2

stack the array over axis=0 should give the result you need:

np.stack(a, axis=0)

Example:

>>> import numpy as np
>>> a = np.empty(3, dtype=object)
>>> a[0] = np.array([[1], [2]])
>>> a[1] = np.array([[3], [4]])
>>> a[2] = np.array([[5], [6]])
>>> a
array([array([[1],
       [2]]), array([[3],
       [4]]),
       array([[5],
       [6]])], dtype=object)
>>> a.shape
(3,)
>>> a[0].shape
(2, 1)
>>> np.stack(a, axis=0)
array([[[1],
        [2]],

       [[3],
        [4]],

       [[5],
        [6]]])
>>> np.stack(a, axis=0).shape
(3, 2, 1)
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.