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?
1 Answer
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)