sort
- sparse.sort(x, /, *, axis=-1, descending=False)[source]
Returns a sorted copy of an input array
x
.- Parameters:
x (SparseArray) – Input array. Should have a real-valued data type.
axis (int) – Axis along which to sort. If set to
-1
, the function must sort along the last axis. Default:-1
.descending (bool) – Sort order. If
True
, the array must be sorted in descending order (by value). IfFalse
, the array must be sorted in ascending order (by value). Default:False
.
- Returns:
out – A sorted array.
- Return type:
- Raises:
ValueError – If the input array isn’t and can’t be converted to COO format.
Examples
>>> import sparse >>> x = sparse.COO.from_numpy([1, 0, 2, 0, 2, -3]) >>> sparse.sort(x).todense() array([-3, 0, 0, 1, 2, 2]) >>> sparse.sort(x, descending=True).todense() array([ 2, 2, 1, 0, 0, -3])