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
From the course: NumPy Essential Training: 1 Foundations of NumPy
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Array types and conversions between types4m 25s
-
(Locked)
Multidimensional arrays3m 7s
-
(Locked)
Creating arrays from lists and other Python structures3m 36s
-
(Locked)
Intrinsic NumPy array creation5m 33s
-
(Locked)
Creating arrays filled with constant values4m 41s
-
(Locked)
Finding the shape and size of an array2m 50s
-
-
-
-