dpnp.sort

dpnp.sort(a, axis=-1, kind=None, order=None, *, descending=False, stable=None)[source]

Return a sorted copy of an array.

For full documentation refer to numpy.sort.

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). If False, 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 to False or None. Internally, this option selects kind="stable".

Default: None.

Returns:
outdpnp.ndarray

Sorted array with the same type and shape as a.

Limitations

Parameters order is only supported with its default value. Otherwise NotImplementedError exception will be raised. Sorting algorithms "quicksort" and "heapsort" are not supported.

See also

dpnp.ndarray.sort

Sort an array in-place.

dpnp.argsort

Return the indices that would sort an array.

dpnp.lexsort

Indirect stable sort on multiple keys.

dpnp.searchsorted

Find elements in a sorted array.

dpnp.partition

Partial sort.

Notes

For zero-dimensional arrays, if axis=None, output is the input array returned as a one-dimensional array. Otherwise, an AxisError is raised.

Examples

>>> import dpnp as np
>>> a = np.array([[1, 4], [3, 1]])
>>> np.sort(a)                # sort along the last axis
array([[1, 4],
       [1, 3]])
>>> np.sort(a, axis=None)     # sort the flattened array
array([1, 1, 3, 4])
>>> np.sort(a, axis=0)        # sort along the first axis
array([[1, 1],
       [3, 4]])