Apply numpy.argsort
on flattened array and then unravel the indices back to (3, 3) shape:
>>> arr = np.array([[5, 2, 4],
[3, 3, 3],
[6, 1, 2]])
>>> np.dstack(np.unravel_index(np.argsort(arr.ravel()), (3, 3)))
array([[[2, 1],
[0, 1],
[2, 2],
[1, 0],
[1, 1],
[1, 2],
[0, 2],
[0, 0],
[2, 0]]])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…