mxnet.np.sort

sort(a, axis=-1, descending=False, stable=True)

Return a sorted copy of an array.

Notes

sort is a standard API in https://data-apis.org/array-api/latest/API_specification/generated/signatures.sorting_functions.sort.html instead of an official NumPy operator.

Parameters
  • a (ndarray) – Array to sort.

  • axis (int or None, optional) – Axis along which to sort. The default is -1 (the last axis). If None, the flattened array is used.

  • descending (bool, optional) – sort order. If True, the returned indices sort x in descending order (by value). If False, the returned indices sort x in ascending order (by value).Default: False.

  • stable (bool, optional) – sort stability. If True, the returned indices must maintain the relative order of x values which compare as equal. If False, the returned indices may or may not maintain the relative order of x values which compare as equal. Default: True.

Returns

sorted_array – Array of the same type and shape as a.

Return type

ndarray

Notes

This operator does not support different sorting algorithms.

Examples

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