2

I got a numpy array with shape (1,3,300), I wanted to get rid of the first axis and get just the 3*300 2D array. How can I do it ?

I saw couple of questions like this numpy with python: convert 3d array to 2d where the requirements are more complex. Mine seems pretty simple. Any eacy way to do it ?

Shew
  • 1,557
  • 1
  • 21
  • 36

1 Answers1

5

np.squeeze ?

In [1]: import numpy as np

In [2]: a = np.arange(3*300).reshape(3,300)

In [3]: a.shape
Out[3]: (3, 300)

In [4]: a = a[np.newaxis, ...]

In [5]: a.shape
Out[5]: (1, 3, 300)

In [6]: b = np.squeeze(a, axis=0)

In [7]: b.shape
Out[7]: (3, 300)
filippo
  • 5,197
  • 2
  • 21
  • 44