Skip to content
Justice Tech School

Fancy Indexing

Pass a list of positions to pick several items in any order.

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

Result

[10 40 20]
[1 8]
[[0 1 2]
 [6 7 8]]

Exercise

List of positions.

a[[0, ]]

Quiz Test

Does fancy indexing copy?

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