I want to convert a numpy array of shape (n,1) to (n,). Is it possible to do this without having to iterate over the array?
Asked
Active
Viewed 4,065 times
1 Answers
1
Use numpy.squeeze
:
>>> x = np.array([[[0], [1], [2]]])
>>> x.shape
(1, 3, 1)
>>> np.squeeze(x).shape
(3,)
>>> np.squeeze(x, axis=(2,)).shape
(1, 3)
I'm pretty sure you could've found this answer from a Google search . . .

abcd
- 10,215
- 15
- 51
- 85