Skip to content
Advertisement

Reshape 3-d array to 2-d

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?

Advertisement

Answer

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]
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement