Course Content
NumPy in a Nutshell
1. Getting Started with NumPy
4. Important Functions
NumPy in a Nutshell
Negative Indexing
We discussed positive indexing, but there is also negative indexing. Negative indexing starts from the end, with index -1
referring to the last element, index -2
referring to the second-to-last element, and so on.
This example illustrates how to retrieve a value of 10 from a given two-dimensional array using negative indexing.
The first index determines the row we choose (-1
refers to the last row), while the second index corresponds to the element we select within that row (-1
is the last one). As a result, we obtain a value of 10
. Run the code above to verify it.
![Example](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/671389bc-34ed-4de7-83cd-2d1bfcf00a76/5.png)
Task
You have the following array:
[[-4, 3, 1], [2, 10, -4]]
. Access the value 10
.
Let's give it a try. Use only negative indices.
Everything was clear?
Course Content
NumPy in a Nutshell
1. Getting Started with NumPy
4. Important Functions
NumPy in a Nutshell
Negative Indexing
We discussed positive indexing, but there is also negative indexing. Negative indexing starts from the end, with index -1
referring to the last element, index -2
referring to the second-to-last element, and so on.
This example illustrates how to retrieve a value of 10 from a given two-dimensional array using negative indexing.
The first index determines the row we choose (-1
refers to the last row), while the second index corresponds to the element we select within that row (-1
is the last one). As a result, we obtain a value of 10
. Run the code above to verify it.
![Example](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/671389bc-34ed-4de7-83cd-2d1bfcf00a76/5.png)
Task
You have the following array:
[[-4, 3, 1], [2, 10, -4]]
. Access the value 10
.
Let's give it a try. Use only negative indices.
Everything was clear?