diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index a8c2fd2fb088..a42904c62ba2 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -890,6 +890,14 @@ def argsort(a, axis=-1, kind='quicksort', order=None): array([[0, 1], [0, 1]]) + Indices of the sorted elements of a N-dimensional array: + >>> np.unravel_index(np.argsort(x, axis=None), x.shape) + (array([0, 1, 1, 0]), array([0, 0, 1, 1])) + >>> from np.testing import assert_equal + >>> assert_equal(x[(array([0, 1, 1, 0]), array([0, 0, 1, 1]))], np.sort(x, axis=None)) + >>> list(zip(*np.unravel_index(np.argsort(x, axis=None), x.shape))) + [(0, 0), (1, 0), (1, 1), (0, 1)] + Sorting with keys: >>> x = np.array([(1, 0), (0, 1)], dtype=[('x', '>> np.argmax(a, axis=1) array([2, 2]) + Indices of the maximal elements of a N-dimensional array: + >>> np.unravel_index(np.argmax(a, axis=None), a.shape) + (1, 2) + >>> np.testing.assert_equal(a[(1, 2)], np.max(a)) + >>> b = np.arange(6) >>> b[1] = 5 >>> b @@ -1008,6 +1021,11 @@ def argmin(a, axis=None, out=None): >>> np.argmin(a, axis=1) array([0, 0]) + Indices of the minimum elements of a N-dimensional array: + >>> np.unravel_index(np.argmin(a, axis=None), a.shape) + (0, 0) + >>> np.testing.assert_equal(a[(0, 0)], np.min(a)) + >>> b = np.arange(6) >>> b[4] = 0 >>> b