From the course: NumPy Essential Training: 1 Foundations of NumPy

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Reshaping arrays

Reshaping arrays

- [Instructor] Reshape is one of the most useful functions you will need to use when you're dealing with multidimensional arrays. It often happens that you create a numpy array in just one dimension and you have to reshape it to multidimensional array later or vice versa. Key concept is change of arrangement of the array so, the shape of the array changes while the number of elements stays the same. Let me go on and show you what I mean in our first example. We have imported numpy as np, let's first create a one-dimensional array of 12 elements using arrange function by typing first arr equals np arrange one 13 and just print it out. Let me go on and show you how to convert it to a two-dimensional array. Reshape function takes as arguments the name of array and the tuple that represents the shape and returns a new two-dimensional view of the past array. We will type second arr equals np.reshape first arr, three, four, and let's print it out. So we have a two-dimensional array that has…

Contents