Skip to content
Justice Tech School

Fancy Indexing

Pass a list of indexes to pick several elements in any order. The result is a copy, not a view.

Example
import numpy as np
a = np.array([10, 20, 30, 40])
print(a[[3, 0, 2]])
m = np.arange(9).reshape(3, 3)
print(m[[0, 2], [1, 1]])

Result

[40 10 30]
[1 7]

Exercise

Pick positions 0 and 2.

a[[0, ]]

Quiz Test

Is fancy indexing a view or copy?

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