Legacy – Creating Different Arrays Workout
- 02:38
Workout demonstrating how to create different NumPy Arrays.
Glossary
Arrays NumPy LibraryTranscript
We now try to gain a bit more knowledge on various kinds of arrays. Before we do anything like always, we need to follow the standard procedure to import the NumPy package. So we say import NumPy as np. So firstly, in order to create an array of zeros, what do we do report a command for that. So we print we use the print command because we want the output to be printed. So we say print np . zeros, three and four. So firstly, we use the np because we're importing the NumPy package as np if we import the numpy packages, and why we use that again. So let's print this Oh, the data type is not understood. Why is that? So it is because we missed out the extra brackets. You see, before writing down three and four, we need to put that in an extra bracket, what does the three and the four stand for the four stands for the number of columns, and the three stands for the number of rows simple. Now, if we want to create an array of ones what we do, which is to follow the same procedure, print np . 1 e is ones we see two comma three, and we give that the data type is equals integer, and p . integer one six, that's the standard procedure of informing the Python NumPy package that we want integers. And one thing that we did wrong over here is that the data type needs to go within the brackets rather than outside the array back brackets because we are trying to say that this particular array needs to be of a particular data type. Now we try to run this. Perfect, we've got an array of two rows and three columns with a data type, which is an integer. Now if we want an array of evenly spaced values, what we do, we use a command which is the alliance space, it's linearly spaced. So we say print np . alliance space. And we define the start number, the end number and how evenly wanted spread say by night, and we try and run this. So we get an array where the starting value is zero and the ending value is a two and it's got evenly spaced. It has been evenly spaced by nine different values. Perfect