You can use argsort to sort the indices of a flattened array, then unravel_index to convert the flat index back to coordinates:
>>> i = (-a).argsort(axis=None, kind='mergesort') >>> j = np.unravel_index(i, a.shape) >>> np.vstack(j).T array([[1, 1], [0, 2], [0, 0], [0, 1], [1, 0], [1, 2]])
-a and kind='mergesort' is to sort the array in a stable manner in descending order (according to the query you are looking for).
If you do not need stable sorting, replace the first line as follows:
>>> i = a.argsort(axis=None)[::-1]
source share