scipp.allsorted#
- scipp.allsorted(x, dim, order='ascending')#
Check if all values of a variable are sorted.
If
orderis ‘ascending’, check if values are non-decreasing alongdim.If
orderis ‘descending’, check if values are non-increasing alongdim.
- Parameters:
- Returns:
bool|DataGroup[object] – True if the variable values are monotonously ascending or descending (depending on the requested order), False otherwise.
See also
Examples
Check if all values are sorted in ascending order:
>>> import scipp as sc >>> x = sc.array(dims=['x'], values=[1, 2, 3, 4, 5]) >>> sc.allsorted(x, 'x') True
Unsorted values return False:
>>> x_unsorted = sc.array(dims=['x'], values=[1, 3, 2, 4, 5]) >>> sc.allsorted(x_unsorted, 'x') False
Check descending order:
>>> x_desc = sc.array(dims=['x'], values=[5, 4, 3, 2, 1]) >>> sc.allsorted(x_desc, 'x', order='descending') True