scipp.issorted#
- scipp.issorted(x, dim, order='ascending')#
Check if the 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:
TypeVar(_T,Variable,DataGroup[object]) – Variable containing one less dim than the original variable with the corresponding boolean value for whether it was sorted along the given dim for the other dimensions.
See also
Examples
Check if a 1-D variable is sorted:
>>> import scipp as sc >>> x = sc.array(dims=['x'], values=[1, 2, 3, 4, 5]) >>> sc.issorted(x, 'x') <scipp.Variable> () bool <no unit> True
Not sorted values return False:
>>> x_unsorted = sc.array(dims=['x'], values=[1, 3, 2, 4, 5]) >>> sc.issorted(x_unsorted, 'x') <scipp.Variable> () bool <no unit> False
For multi-dimensional data, returns a result with one less dimension:
>>> data_2d = sc.array(dims=['x', 'y'], values=[[1, 2, 3], [4, 5, 6]]) >>> sc.issorted(data_2d, 'y') <scipp.Variable> (x: 2) bool <no unit> [True, True]