Repository navigation
Expand file tree
/
Copy pathsorting_functions.py
More file actions
62 lines (48 loc) · 3.49 KB
/
Copy pathsorting_functions.py
File metadata and controls
62 lines (48 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
__all__ = ["argsort", "sort"]
from ._types import array
def argsort(
x: array, /, *, axis: int = -1, descending: bool = False, stable: bool = True
) -> array:
"""
Returns the indices that sort an array ``x`` along a specified axis.
Parameters
----------
x: array
input array. **Should** have a real-valued data type.
axis: int
axis along which to sort. A valid axis **must** be an integer on the interval ``[-N, N)``, where ``N`` is the number of axes in ``x``. If an axis is specified as a negative integer, the function **must** determine the axis along which to perform the operation by counting backward from the last axis (where ``-1`` refers to the last axis). If provided an invalid axis, the function **must** raise an exception. Default: ``-1``.
descending: bool
sort order. If ``True``, the returned indices **must** sort ``x`` in descending order (by value). If ``False``, the returned indices **must** sort ``x`` in ascending order (by value). Default: ``False``.
stable: bool
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** maintain the relative order of ``x`` values which compare as equal (i.e., the relative order of ``x`` values which compare as equal is implementation-dependent). Default: ``True``.
Returns
-------
out: array
an array of indices. The returned array **must** have the same shape as ``x``. The returned array **must** have the default array index data type.
Notes
-----
- For backward compatibility, conforming implementations **may** support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent (see :ref:`complex-number-ordering`).
"""
def sort(
x: array, /, *, axis: int = -1, descending: bool = False, stable: bool = True
) -> array:
"""
Returns a sorted copy of an input array ``x``.
Parameters
----------
x: array
input array. **Should** have a real-valued data type.
axis: int
axis along which to sort. A valid axis **must** be an integer on the interval ``[-N, N)``, where ``N`` is the number of axes in ``x``. If an axis is specified as a negative integer, the function **must** determine the axis along which to perform the operation by counting backward from the last axis (where ``-1`` refers to the last axis). If provided an invalid axis, the function **must** raise an exception. Default: ``-1``.
descending: bool
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: bool
sort stability. If ``True``, the returned array **must** maintain the relative order of ``x`` values which compare as equal. If ``False``, the returned array **may** maintain the relative order of ``x`` values which compare as equal (i.e., the relative order of ``x`` values which compare as equal is implementation-dependent). Default: ``True``.
Returns
-------
out: array
a sorted array. The returned array **must** have the same data type and shape as ``x``.
Notes
-----
- For backward compatibility, conforming implementations **may** support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-dependent (see :ref:`complex-number-ordering`).
"""