NumPy Reshaping

Reshaping allows to change the shape of an array. For example, we can reshape a two dimensional array into a one dimensional one and vice versa

 

 

Change a one dimensional array into two dimensional

We can use the reshape method to covert a one dimensional array into two dimensional array.

The above code will output this result

[ 1 2 3 4 5 6 7 8 9 10]

array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10]])

Change a two dimensional array into one dimensional

We can use the flatten method to covert a multi dimensional array into 1 dimensional array.

The above code will output this result

[[1 2 3]
[4 5 6]]

array([1, 2, 3, 4, 5, 6])