Sorting

arkouda.argsort(pda, algorithm=SortingAlgorithm.RadixSortLSD, axis=0)[source]

Return the permutation that sorts the array.

Parameters:

pda (pdarray or Strings or Categorical) – The array to sort (int64, uint64, or float64)

Returns:

The indices such that pda[indices] is sorted

Return type:

pdarray, int64

Raises:

TypeError – Raised if the parameter is other than a pdarray or Strings

See also

coargsort

Notes

Uses a least-significant-digit radix sort, which is stable and resilient to non-uniformity in data but communication intensive.

Examples

>>> a = ak.randint(0, 10, 10)
>>> perm = ak.argsort(a)
>>> a[perm]
array([0, 1, 1, 3, 4, 5, 7, 8, 8, 9])
arkouda.coargsort(arrays, algorithm=SortingAlgorithm.RadixSortLSD)[source]

Return the permutation that groups the rows (left-to-right), if the input arrays are treated as columns. The permutation sorts numeric columns, but not strings/Categoricals – strings/Categoricals are grouped, but not ordered.

Parameters:

arrays (Sequence[Union[Strings, pdarray, Categorical]]) – The columns (int64, uint64, float64, Strings, or Categorical) to sort by row

Returns:

The indices that permute the rows to grouped order

Return type:

pdarray, int64

Raises:

ValueError – Raised if the pdarrays are not of the same size or if the parameter is not an Iterable containing pdarrays, Strings, or Categoricals

See also

argsort

Notes

Uses a least-significant-digit radix sort, which is stable and resilient to non-uniformity in data but communication intensive. Starts with the last array and moves forward. This sort operates directly on numeric types, but for Strings, it operates on a hash. Thus, while grouping of equivalent strings is guaranteed, lexicographic ordering of the groups is not. For Categoricals, coargsort sorts based on Categorical.codes which guarantees grouping of equivalent categories but not lexicographic ordering of those groups.

Examples

>>> a = ak.array([0, 1, 0, 1])
>>> b = ak.array([1, 1, 0, 0])
>>> perm = ak.coargsort([a, b])
>>> perm
array([2, 0, 3, 1])
>>> a[perm]
array([0, 0, 1, 1])
>>> b[perm]
array([0, 1, 0, 1])