array_is_monotonic

halotools.utils.array_is_monotonic(array, strict=False)[source] [edit on github]

Method determines whether an input array is monotonic.

Parameters:

array : array_like

strict : bool, optional

If set to True, an array must be strictly monotonic to pass the criteria. Default is False.

Returns:

flag : int

If input array is monotonically increasing, the returned flag = 1; if array is monotonically decreasing, flag = -1. Otherwise, flag = 0.

Notes

If the input array is constant-valued, method returns flag = 1.

Examples

>>> x = np.linspace(0, 10, 100)
>>> assert array_is_monotonic(x) == 1
>>> assert array_is_monotonic(x[::-1]) == -1
>>> y = np.ones(100)
>>> assert array_is_monotonic(y) == 1
>>> assert array_is_monotonic(y, strict=True) == 0