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.

Creating arrays filled with constant values

Creating arrays filled with constant values

- [Narrator] Sometimes you want to create specific types of arrays filled with constant values. NumPy provides us with functions, to achieve that easily. For example, if you want to generate arrays of all zeros, we can call zeros function. First, let's import NumPy as np, and then create our first nd arrays using the zeros function. We'll call our array first z array and pass in a single integer to get 1 dimensional array. Let's pass 5 and we have an array of 0,0,0,0,0. We can also create 2 dimensional nd array, if you pass a topple of dimensions we want. In this case, the first number will represent the number of rows, and the second number will represent the number of columns. So let's create our 2 dimensional array, and call it second z array, and pass topple 4, 5. And there we have an array with 4 rows and 5 columns. Second useful function is ones, and you can probably guess we'll use it to create an array of pure ones. We'll use it the same way as we used the zeros function. For…

Contents