dpnp.sort

dpnp.sort(a, axis=-1, kind=None, order=None, *, 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.

  • kind ({None, "stable", "mergesort", "radixsort"}, optional) -- Sorting algorithm. Default is None, which is equivalent to "stable".

  • 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:

out -- Sorted array with the same type and shape as a.

Return type:

dpnp.ndarray

Notes

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

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.

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]])