Sorting¶
- arkouda.argsort(pda, algorithm=SortingAlgorithm.RadixSortLSD, axis=0)[source]¶
Return the permutation that sorts the array.
- Parameters:
pda (pdarray, Strings, or Categorical) – The array to sort (int64, uint64, or float64)
algorithm (SortingAlgorithm, default=SortingAlgorithm.RadixSortLSD) – The algorithm to be used for sorting the array.
axis (int_scalars, default=0) – The axis to sort over.
- Returns:
The indices such that
pda[indices]
is sorted- Return type:
- Raises:
TypeError – Raised if the parameter is other than a pdarray, Strings or Categorical
See also
Notes
Uses a least-significant-digit radix sort, which is stable and resilient to non-uniformity in data but communication intensive.
Examples
>>> import arkouda as ak >>> a = ak.randint(0, 10, 10, seed=1) >>> a array([7 9 5 1 4 1 8 5 5 0])
>>> perm = ak.argsort(a) >>> a[perm] array([0 1 1 4 5 5 5 7 8 9])
>>> ak.argsort(a, ak.sorting.SortingAlgorithm["RadixSortLSD"]) array([9 3 5 4 2 7 8 0 6 1])
>>> ak.argsort(a, ak.sorting.SortingAlgorithm["TwoArrayRadixSort"]) array([9 3 5 4 2 7 8 0 6 1])
- arkouda.coargsort(arrays, algorithm=SortingAlgorithm.RadixSortLSD, ascending=True)[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 or Categoricals — those are grouped, not ordered.
- Parameters:
arrays (Sequence of Strings, pdarray, or Categorical) – The columns (int64, uint64, float64, Strings, or Categorical) to sort by row.
algorithm (SortingAlgorithm, default=SortingAlgorithm.RadixSortLSD) – The algorithm to be used for sorting the arrays.
ascending (bool, default=True) – Whether to sort in ascending order. Ignored when arrays have ndim > 1.
- Returns:
The indices that permute the rows into grouped order.
- Return type:
- Raises:
ValueError – If the inputs are not all the same size or not valid array types.
See also
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.
For Strings, sorting is based on a hash. This ensures grouping of identical strings, but not lexicographic order. For Categoricals, sorting is based on the internal codes.
Examples
>>> import arkouda as ak >>> 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])