AtomLearnAtomLearn
DashboardGoalsPathAchievementsReviewSign In
DashboardNumPyArray Indexing
NumPyNot Started

Array Indexing

Accessing individual elements and rows/columns by position

0%
Knowledge0%
Learn & Drill
Fluency0%
Drill & Speed
Retention0%
Mastery & Review
Confidence0%
All modes
Practice
Knowledge
Fluency
Retention

Knowledge Debt detected

You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.

Explanation

NumPy indexing works like Python lists for 1D, and extends naturally to multiple dimensions.

1D indexing:

python a = np.array([10, 20, 30, 40, 50]) a[0] # 10 (first) a[-1] # 50 (last) a[-2] # 40 (second to last)

2D indexing — [row, col]:

python m = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) m[0, 0] # 1 (top-left) m[1, 2] # 6 (row 1, col 2) m[-1, -1] # 9 (bottom-right) m[0] # [1, 2, 3] (entire first row) m[:, 1] # [2, 5, 8] (entire second column)

Examples

Row and column access

The colon : means "all" for that dimension

import numpy as np

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

print(m[1, 2])    # 6
print(m[2])       # [7 8 9] — row 2
print(m[:, 0])    # [1 4 7] — col 0
print(m[-1, -1])  # 9

How well did you understand this?

Next in NumPy

Array Slicing

Continue