Miscellaneous Utilities (dorado.scheduling.utils)#
Miscellaneous utilities.
- dorado.scheduling.utils.nonzero_intervals(a)#
Find the intervals over which an array is nonzero.
- Parameters:
a (numpy.ndarray) – A 1D array of length N.
- Returns:
indices – An array of size (N, 2) denoting the start and end indices of the intervals with contiguous nonzero values in a.
- Return type:
numpy.ndarray
Examples
>>> nonzero_intervals([]) array([], shape=(0, 2), dtype=int64) >>> nonzero_intervals([0, 0, 0, 0]) array([], shape=(0, 2), dtype=int64) >>> nonzero_intervals([1, 1, 1, 1]) array([[0, 3]]) >>> nonzero_intervals([0, 1, 1, 1]) array([[1, 3]]) >>> nonzero_intervals([1, 1, 1, 0]) array([[0, 2]]) >>> nonzero_intervals([1, 1, 0, 1, 0, 1, 1, 1]) array([[0, 1], [3, 3], [5, 7]])