scipp.allsorted#

scipp.allsorted(x, dim, order='ascending')#

Check if all values of a variable are sorted.

  • If order is ‘ascending’, check if values are non-decreasing along dim.

  • If order is ‘descending’, check if values are non-increasing along dim.

Parameters:
  • x (Variable | DataGroup[object]) – Variable to check.

  • dim (str) – Dimension along which order is checked.

  • order (Literal['ascending', 'descending'], default: 'ascending') – Sorting order.

Returns:

bool | DataGroup[object] – True if the variable values are monotonously ascending or descending (depending on the requested order), False otherwise.

See also

scipp.issorted

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