Skip to content

Commit

Permalink
Merge pull request numpy#12929 from Milania1/docs/np-argsort
Browse files Browse the repository at this point in the history
DOC: fix documentation bug in np.argsort and extend examples
  • Loading branch information
mattip authored Feb 7, 2019
2 parents 76a76c7 + 316c5fe commit bf00ee5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions numpy/core/fromnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ def argsort(a, axis=-1, kind='quicksort', order=None):
Returns
-------
index_array : ndarray, int
Array of indices that sort `a` along the specified axis.
Array of indices that sort `a` along the specified `axis`.
If `a` is one-dimensional, ``a[index_array]`` yields a sorted `a`.
More generally, ``np.take_along_axis(a, index_array, axis=a)`` always
yields the sorted `a`, irrespective of dimensionality.
More generally, ``np.take_along_axis(a, index_array, axis=axis)``
always yields the sorted `a`, irrespective of dimensionality.
See Also
--------
Expand Down Expand Up @@ -1013,13 +1013,21 @@ def argsort(a, axis=-1, kind='quicksort', order=None):
array([[0, 3],
[2, 2]])
>>> np.argsort(x, axis=0) # sorts along first axis (down)
>>> 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]])
>>> np.argsort(x, axis=1) # sorts along last axis (across)
>>> ind = np.argsort(x, axis=1) # sorts along last axis (across)
>>> ind
array([[0, 1],
[0, 1]])
>>> np.take_along_axis(x, ind, axis=1) # same as np.sort(x, axis=1)
array([[0, 3],
[2, 2]])
Indices of the sorted elements of a N-dimensional array:
Expand Down

0 comments on commit bf00ee5

Please sign in to comment.