arkouda.sorting

Module Contents

Functions

argsort(→ arkouda.pdarrayclass.pdarray)

Return the permutation that sorts the array.

coargsort(→ arkouda.pdarrayclass.pdarray)

Return the permutation that groups the rows (left-to-right), if the

sort(→ arkouda.pdarrayclass.pdarray)

Return a sorted copy of the array. Only sorts numeric arrays;

arkouda.sorting.argsort(pda: arkouda.pdarrayclass.pdarray | arkouda.strings.Strings | arkouda.categorical.Categorical, algorithm: SortingAlgorithm = SortingAlgorithm.RadixSortLSD, axis: arkouda.dtypes.int_scalars = 0) arkouda.pdarrayclass.pdarray[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.sorting.coargsort(arrays: Sequence[arkouda.strings.Strings | arkouda.pdarrayclass.pdarray | arkouda.categorical.Categorical], algorithm: SortingAlgorithm = SortingAlgorithm.RadixSortLSD) arkouda.pdarrayclass.pdarray[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])
arkouda.sorting.sort(pda: arkouda.pdarrayclass.pdarray, algorithm: SortingAlgorithm = SortingAlgorithm.RadixSortLSD) arkouda.pdarrayclass.pdarray[source]

Return a sorted copy of the array. Only sorts numeric arrays; for Strings, use argsort.

Parameters:

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

Returns:

The sorted copy of pda

Return type:

pdarray, int64, uint64, or float64

Raises:
  • TypeError – Raised if the parameter is not a pdarray

  • ValueError – Raised if sort attempted on a pdarray with an unsupported dtype such as bool

See also

argsort

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)
>>> sorted = ak.sort(a)
>>> a
array([0, 1, 1, 3, 4, 5, 7, 8, 8, 9])