I want to change my array type as pd.DataFrame
but its shape is:
JavaScript
x
3
1
array_.shape
2
(1, 181, 12)
3
I’ve tried to reshape by the following code, but it didn’t work:
JavaScript
1
2
1
new_arr = np.reshape(array_, (-1, 181, 12))
2
How can I change its shape?
Advertisement
Answer
NumPy array dimensions can be reduced using various ways; some are:
using np.squeeze
:
JavaScript
1
2
1
array_.squeeze(0)
2
using np.reshape
:
JavaScript
1
2
1
array_.reshape(array_.shape[1:])
2
or with using -1
in np.reshape
:
JavaScript
1
4
1
array_.reshape(-1, m.shape[-1])
2
3
# new_arr = np.reshape(array_, (-1, 12)) # <== change to your code
4
using indexing
as Szczesny’s comment:
JavaScript
1
2
1
array_[0]
2