Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Access 2-D Arrays

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.

Example

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[01])

Example

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[14])