To access elements in two-dimensional (2-D) arrays, we can use comma-separated integers that specify the dimension and the index of the element. You can think of 2-D arrays as tables with rows and columns, where the dimension indicates the row and the index refers to the column.
Access the element located in the first row and second column.
import numpy as np arr = np.array([[1,2,3,4,5], [6,7,8,9,10]]) print(‘2nd element on 1st row: ‘, arr[0, 1]) |
Access the element in the second row and fifth column.
import numpy as np arr = np.array([[1,2,3,4,5], [6,7,8,9,10]]) print(‘5th element on 2nd row: ‘, arr[1, 4]) |