Rows and Columns With Negative Indexes
Do you know how negative indexes are represented in Python? Remember from the Python tutorial? No? No worries, let's go through it again:
Using Negative Single Index
- Using negative indexing on 1-D array
- Pass the negative index of the element in a square bracket [ ].
- Using negative indexing on 2-D array
- Pass the negative index of the element in a square bracket [].
- Try executing num_arr[-1][-2] in your notebook
Negative Index Intervals
- Now you have an idea about how index intervals work on a NumPy array.
- You also have an idea about how negative indexing works on Python lists.
- See the snippet shown here. Can you think of how to get the output in yellow box using negative indexing? Try doing this on your own first.
- The following code didn't give the correct solution. Can you figure out why?
- Here's the correct solution. Phew!