array_is_monotonic

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

Method determines whether an input array is monotonic.

Parameters:
arrayarray_like
strictbool, optional

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

Returns:
flagint

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