...

/

NumPy Basics - Reshaping and Concatenation

NumPy Basics - Reshaping and Concatenation

5. Reshaping of Arrays

Reshaping is about changing the way items are arranged within the array so that the shape of the array changes, but the total number of elements in both arrays remains the same, e.g., you can use it to convert a 1D array into 2D array.

Reshaping is a very useful operation and it can easily be done using the reshape() method. Since a picture speaks a thousand words, let’s see the effects of reshaping visually:

Reshaping example (Image credits: www.3resource.com)
Reshaping example (Image credits: www.3resource.com)

How can we do this in code? Say we want to create a 3x3 grid with numbers from 1 to 9. We first create a 1D array and then convert it to the desired shape as ...

Access this course and 1400+ top-rated courses and projects.