dpnp.argsort
- dpnp.argsort(a, axis=-1, kind=None, order=None)[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 (int or None, 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) -- Default is
None, which is equivalent to "stable". Unlike in NumPy any other options are not accepted here.
- 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, an
AxisErroris raised.Limitations
Parameters order is only supported with its default value. Parameters 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]])