# Python program explaining
# argpartition() function
import numpy as geek
# input array
in_arr = geek.array([ 2, 0, 1, 5, 4, 1, 9])
print ("Input unsorted array : ", in_arr)
out_arr = geek.argsort(in_arr)
print ("Output sorted array indices : ", out_arr)
print("Output sorted array : ", in_arr[out_arr])
x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])
ind = np.argsort(x, axis=0) # sorts along first axis (down)
ind
array([[0, 1],
[1, 0]])
np.take_along_axis(x, ind, axis=0) # same as np.sort(x, axis=0)
array([[0, 2],
[2, 3]])
x = np.array([[0, 3], [2, 2]])
x
array([[0, 3],
[2, 2]])