1x = np.array([[0,3],[2,2]])
2
3>>> ind = np.argsort(x, axis=1) # sorts along last axis (across)
4>>> ind
5array([[0, 1],
6 [0, 1]])
7>>> np.take_along_axis(x, ind, axis=1) # same as np.sort(x, axis=1)
8array([[0, 3],
9 [2, 2]])
10
1def g(seq):
2 # http://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python/3383106#3383106
3 #lambda version by Tony Veijalainen
4 return [x for x,y in sorted(enumerate(seq), key = lambda x: x[1])]