merge_intervals#
- mobgap.utils.array_handling.merge_intervals(input_array: ndarray, gap_size: int = 0) ndarray[source]#
Merge intervals that are overlapping and that are a distance less or equal to gap_size from each other.
This is actually a wrapper for _solve_overlap that is needed because numba can not compile np.sort().
- Parameters:
- input_array(n, 2) np.ndarray
The np.ndarray containing the intervals that should be merged
- gap_sizeint
Integer that sets the allowed gap between intervals. For examples see below. Default is 0.
- Returns:
- merged intervals array
(n, 2) np.ndarray containing the merged intervals
Examples
>>> test = np.array([[1, 3], [2, 4], [6, 8], [5, 7], [10, 12], [11, 15], [18, 20]]) >>> merge_intervals(test) array([[ 1, 4], [ 5, 8], [10, 15], [18, 20]])
>>> merge_intervals(test, 2) array([[ 1, 15], [18, 20]])