Return a sorted copy of an array. Parameters ---------- a : array_like 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
(a, axis=-1, kind=None, order=None, *, stable=None, descending=np._NoValue)
| 940 | |
| 941 | @array_function_dispatch(_sort_dispatcher) |
| 942 | def sort(a, axis=-1, kind=None, order=None, *, stable=None, descending=np._NoValue): |
| 943 | """ |
| 944 | Return a sorted copy of an array. |
| 945 | |
| 946 | Parameters |
| 947 | ---------- |
| 948 | a : array_like |
| 949 | Array to be sorted. |
| 950 | axis : int or None, optional |
| 951 | Axis along which to sort. If None, the array is flattened before |
| 952 | sorting. The default is -1, which sorts along the last axis. |
| 953 | kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional |
| 954 | Sorting algorithm. The default is 'quicksort'. Note that both 'stable' |
| 955 | and 'mergesort' use timsort or radix sort under the covers and, |
| 956 | in general, the actual implementation will vary with data type. |
| 957 | The 'mergesort' option is retained for backwards compatibility. |
| 958 | order : str or list of str, optional |
| 959 | When `a` is an array with fields defined, this argument specifies |
| 960 | which fields to compare first, second, etc. A single field can |
| 961 | be specified as a string, and not all fields need be specified, |
| 962 | but unspecified fields will still be used, in the order in which |
| 963 | they come up in the dtype, to break ties. |
| 964 | stable : bool, optional |
| 965 | Sort stability. If ``True``, the returned array will maintain |
| 966 | the relative order of ``a`` values which compare as equal. |
| 967 | If ``False`` or ``None``, this is not guaranteed. Internally, |
| 968 | this option selects ``kind='stable'``. Default: ``None``. |
| 969 | |
| 970 | .. versionadded:: 2.0.0 |
| 971 | descending : bool, optional |
| 972 | Sort order. If ``True``, the returned array will be sorted in |
| 973 | descending order. If ``False`` or ``None``, the returned array will |
| 974 | be sorted in ascending order. Values that are NaN are sorted to the |
| 975 | end for both orders. Default: ``None``. |
| 976 | |
| 977 | .. versionadded:: 2.5.0 |
| 978 | |
| 979 | Returns |
| 980 | ------- |
| 981 | sorted_array : ndarray |
| 982 | Array of the same type and shape as `a`. |
| 983 | |
| 984 | See Also |
| 985 | -------- |
| 986 | ndarray.sort : Method to sort an array in-place. |
| 987 | argsort : Indirect sort. |
| 988 | lexsort : Indirect stable sort on multiple keys. |
| 989 | searchsorted : Find elements in a sorted array. |
| 990 | partition : Partial sort. |
| 991 | |
| 992 | Notes |
| 993 | ----- |
| 994 | The various sorting algorithms are characterized by their average speed, |
| 995 | worst case performance, work space size, and whether they are stable. A |
| 996 | stable sort keeps items with the same key in the same relative |
| 997 | order. The four algorithms implemented in NumPy have the following |
| 998 | properties: |
| 999 |
no test coverage detected
searching dependent graphs…