How to Access Elements From 2-D NumPy Arrays


In this example we will show how to access elements from 2-D NumPy arrays using the array indexing in Python.

Source Code

import numpy as np

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

print('The first element of the first dimension:', n[0, 0])
print('The third element of the second dimension:', n[1, 2])

Output:

The first element of the first dimension: 1
The third element of the second dimension: 7
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments