-4

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
  • 7,491
  • 7
  • 41
  • 60

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 . . .

dbliss
  • 9,270
  • 15
  • 46
  • 80