0

I want to change my array type as pd.DataFrame but its shape is:

array_.shape
(1, 181, 12)

I've tried to reshape by the following code, but it didn't work:

new_arr = np.reshape(array_, (-1, 181, 12))

How can I change its shape?

Ali_Sh
  • 2,667
  • 3
  • 43
  • 66

2 Answers2

2

NumPy array dimensions can be reduced using various ways; some are:
using np.squeeze:

array_.squeeze(0)

using np.reshape:

array_.reshape(array_.shape[1:])

or with using -1 in np.reshape:

array_.reshape(-1, m.shape[-1])

# new_arr = np.reshape(array_, (-1, 12))    # <==   change to your code

using indexing as Szczesny's comment:

array_[0]
Ali_Sh
  • 2,667
  • 3
  • 43
  • 66
0

You may want to erase the -1 parameter from the reshape() function to get a final output shape of (181, 12)

import numpy as np

m = np.array([[[1]*12]*181])
n = np.reshape(m, (181, 12))
print(m.shape, n.shape)

Output:

(1, 181, 12) (181, 12)
Cardstdani
  • 4,999
  • 3
  • 12
  • 31