Tsallaka zuwa abun ciki
Justice Tech School

Sorting and Searching

sort returns a sorted copy. argsort gives the order of indexes. searchsorted finds insert positions in sorted data and where finds matches.

Example
import numpy as np
a = np.array([3, 1, 2])
print(np.sort(a), np.argsort(a))
print(np.searchsorted([1, 3, 5], 4))
print(np.where(a > 1))
print(np.argmax(a), np.argmin(a))

Result

[1 2 3] [1 2 0]
2
(array([0, 2]),)
0 1

Exercise

Indexes that sort.

np.(a)

Quiz Test

What does argmax return?

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