Let’s see how to use numpy reshape method to reshape an array in Numpy Python module.
Reshaping an array
Suppose you would like to reshape a one-dimensional array into a four-dimensional one.
import numpy as np my_array = np.arange(24) reshaped_array = my_array.reshape(4, 6) print("my array") print(my_array) print("reshaped array") print(reshaped_array)
I used the np.reshape function. The first element is the new number of dimensions.
In other words, the first argument will be the number of rows and the second one will be the number of columns.