Tsallaka zuwa abun ciki
Justice Tech School

sort, argsort and unique

sort orders values, argsort gives the order and unique finds distinct values.

Example
a = np.array([3, 1, 2, 3, 1])
print(np.sort(a))
print(np.argsort(a))
print(np.unique(a, return_counts=True))

Result

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

Exercise

Order of indexes.

np.(a)

Quiz Test

What does argsort return?

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