make_intervals
- dtaianomaly.utils.make_intervals(x: ~numpy.array) -> (<built-in function array>, <built-in function array>)[source]
Numba implementation to convert an array into intervals.
Given a binary array, i.e., an array consisting of only 0’s and 1’s, this method will extract all intervals of consecutive o1’s from the array. The start-index corresponds to the index (0-based) of the first 1 in the interval, the end-index is the index of the last 1 in the interval. The method outputs two independent arrays, one for the start indices and one for the end incides.
- Parameters:
- xnp.array
The array from which the intervals must be computed. The array should consist of solely 0’s and 1’s.
- Returns:
- starts: np.array of shape (I,)
The start index of each interval. In total, there are I intervals.
- ends: np.array of shape (I,)
The end index of each interval. In total, there are I intervals.
Examples
>>> import numpy as np >>> from dtaianomaly.utils import make_intervals >>> starts, ends = make_intervals(np.array([0, 1, 1, 1, 0, 0, 1, 0])) >>> starts array([1, 6]) >>> ends array([3, 6])