mqr.spc.util.

group_consecutives#

mqr.spc.util.group_consecutives(array, is_consecutive=None)#

Groups the index of an array to form sets of consecutive values.

Parameters:
arrayarray_like[T]

Values with possible consecutive elements.

is_consecutiveCallable[[T, T], bool]

A function returning True if its two arguments are consecutive.

Returns:
list[T]

Examples

>>> consecutive_rule = lambda a, b: b == a + 1
>>> mqr.spc.util.group_consecutives(
        np.array([1, 2, 4, 6, 7, 8, 10]),
        consecutive_rule)
[array([1, 2]), array([4]), array([6, 7, 8]), array([10])]