-5

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?

Jadiel de Armas
  • 8,405
  • 7
  • 46
  • 62

1 Answers1

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