Skip to content
Justice Tech School

Array Indexing

Use zero based indexes. For two dimensions write a[row, col]. Negative indexes count from the end.

Example
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a[0, 1], a[1, -1])
print(a[1])
print(a[:, 2])

Result

2 6
[4 5 6]
[3 6]

Exercise

Row 0, column 2.

a[0, ]

Quiz Test

Which index is the last element?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.