How to Access Elements From NumPy Arrays Using Negative Indexing


In this example we will show how to access elements from the NumPy arrays using negative indexing in Python.

Source Code

import numpy as np

n = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])

print('The last element of the first array:', n[0, -1])

Output:

The last element of the first array: 4
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments