dpnp.argsort¶
- dpnp.argsort(a, axis=-1, kind=None, order=None, *, descending=False, stable=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{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.Default:
-1.- kind{None, "stable", "mergesort", "radixsort"}, optional
Sorting algorithm. The default is
None, which uses parallel merge-sort or parallel radix-sort algorithms depending on the array data type.Default:
None.- descendingbool, optional
Sort order. If
True, the array must be sorted in descending order (by value). IfFalse, the array must be sorted in ascending order (by value).Default:
False.- stable{None, bool}, optional
Sort stability. If
True, the returned array will maintain the relative order of a values which compare as equal. The same behavior applies when set toFalseorNone. Internally, this option selectskind="stable".Default:
None.
- Returns:
- outdpnp.ndarray
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.
Limitations
Parameter order is only supported with its default value. Otherwise
NotImplementedErrorexception will be raised. Sorting algorithms"quicksort"and"heapsort"are not supported.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.
Notes
For zero-dimensional arrays, if
axis=None, output is a one-dimensional array with a single zero element. Otherwise, anAxisErroris raised.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]])