Reshaping an array in NumPy means to change its dimensions. We can even convert a One — Dimensional array to a Multidimensional array.

For reshape to work successfully, the size of the original array must match the size of the reshaped array.

Let us begin by trying out some examples.

We first create a NumPy array of size 8. Note that, now we can reshape it to other arrays of size 8 only.

Reshaping to an array of 2 rows and 4 columns

Reshaping to an array of 1 row and 8 columns

Reshaping to an array of 8 rows and 1 column

We can see that in all the above cases, what we get after reshaping is still an array of size 8. Why? Because the number of elements in the array will be the same before and after reshaping it.