dpnp.argsort
- dpnp.argsort(a, axis=-1, kind=None, order=None, *, stable=True)[source]
Returns the indices that would sort an array.
For full documentation refer to
numpy.argsort.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- Array to be sorted.
axis ({None, int}, optional) -- Axis along which to sort. If
None, the array is flattened before sorting. The default is-1, which sorts along the last axis.kind ({None, "stable"}, optional) --
- Sorting algorithm. Default is
None, which is equivalent to "stable". Unlike NumPy, no other option is accepted here.
- Sorting algorithm. Default is
stable ({None, bool}, optional) -- Sort stability. If
True, the returned array will maintain the relative order ofavalues which compare as equal. The same behavior applies when set toFalseorNone. Internally, this option selectskind="stable". Default:None.
- Returns:
out -- Array of indices that sort a along the specified axis. If a is one-dimensional,
a[index_array]yields a sorted a. More generally,dpnp.take_along_axis(a, index_array, axis=axis)always yields the sorted a, irrespective of dimensionality. The return array has default array index data type.- Return type:
dpnp.ndarray
Notes
For zero-dimensional arrays, if
axis=None, output is a one-dimensional array with a single zero element. Otherwise, anAxisErroris raised.Limitations
Parameters order is only supported with its default value. Parameter kind can only be
Noneor"stable"which are equivalent. OtherwiseNotImplementedErrorexception will be raised.See also
dpnp.ndarray.argsortEquivalent method.
dpnp.sortReturn a sorted copy of an array.
dpnp.lexsortIndirect stable sort with multiple keys.
dpnp.argpartitionIndirect partial sort.
dpnp.take_along_axisApply
index_arrayfrom obj:dpnp.argsort to an array as if by calling sort.
Examples
>>> import dpnp as np >>> x = np.array([3, 1, 2]) >>> np.argsort(x) array([1, 2, 0])
>>> x = np.array([[0, 3], [2, 2]]) >>> x array([[0, 3], [2, 2]])
>>> ind = np.argsort(x, axis=0) # sorts along first axis >>> 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]])
>>> ind = np.argsort(x, axis=1) # sorts along last axis >>> 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]])