Indexing And NUMPY
Hello Guys! Lets start Learning 😃.
print("Welcome to world of Numpy 😄")Before we deep dive into Indexing, lets have a bonus!
Umm… you MIGHT be wondering is it creating spaces between line or what? 😆
NO!
Lemme Demonstrate the Output first.
This method created an array, containing 10 integer values, starting from 30, and ending on 70, as per the requirement it can vary, and easily implemented 🤓.
Coming back to topic!
Indexing
Creating an array by calling a function named arange and mentioning as argument that we desire an array containing values starting from 0 till 11, Ofc excluding 11.
Lets implement Indexing!
Yes! In first loc (Line of Code) we asked for the value that lies on 4th index inside the array named array, then in Second statement we asked for negative 2nd position.
Get Mian’s stories in your inbox
Join Medium for free to get updates from this writer.
But Before we get the result, lemme share with you, array could negatively indexed!
Yes you heard me correct 😃!
Negative sign indicates that you start reading from the trailing end of array.
I am thinking what you are thinking! array[4] shouldn’t be the value 3, since its the 4th value in array!
Here is the twist, from left side of array, Indexing start from 0 and right side indexing start from -1.
LET’S DO SOMETHING MORE CRAZY!
Lets create an array, and reshape it into Two Dimensions.
This is how the 2D array looks like.
The array is index row and column wise.
“ : 3” indicates that from very first row till 2nd row, the second portion of indexing, which begins after “ , ” is for columns, and its tells to index and get the values in array from 1st column till 2nd column.
You might have noticed that last values in indexing such as in row’s indexing values of 3rd rows were not part of rows, same as in for part column indexing value 3rd column was ignored, and this is expected behaviour not an error.
So these were foundations for understanding indexing using NUMPY. Don’t forget to explore at your own 🤓.
print("Yes I got it :D")







