Legacy – Inspecting Arrays Workout
- 02:04
Workout demonstrating how to inspect NumPy Arrays.
Downloads
Inspecting Arrays - Python Workout FilesTranscript
We can certainly inspect the array that we're using. In order to do that, firstly, we need an array. So to create an array, we need to import the NumPy package like usual. To do that, let's do import NumPy as np then the next plan is to create an array. So let us create an array a by np . array, and it consists of values one, two, and three. Let's run this. Perfect, no errors returned. Next, if we want to know the shape of the array or the array dimensions, we use the command a . shape, which essentially returns the shape of the array, we run it. So basically, this array has got three rows and one column. Then if we want the length of the array a, we print this. So essentially, this would give us the length of the array meaning the number of elements inside the array, which is three. Perfect. If we want to know the number of array dimensions, we use the command a . n dim. Dim stands for dimensions. So there is one dimension to the array. Exactly, because it's a one dimensional array because there aren't any more dimensions. Next, we can also find out the number of array elements by a . size. Excellent, three elements insider, which is correct. We've got one, two and three. And finally, if we want to know the datatype of the array elements, we say a . d type and we run it. Excellent. It's an integer