bool_array_to_start_end_array#
- mobgap.utils.array_handling.bool_array_to_start_end_array(bool_array: ndarray) ndarray[source]#
Find regions in bool array and convert those to start-end indices.
The end index is the first element after the True-region, so you can use it for upper-bound exclusive slicing etc.
- Parameters:
- bool_arrayarray with shape (n,)
boolean array with either 0/1, 0.0/1.0 or True/False elements
- Returns:
- array of [start, end] indices with shape (n,2)
Examples
>>> example_array = np.array([0, 0, 1, 1, 0, 0, 1, 1, 1]) >>> start_end_list = bool_array_to_start_end_array(example_array) >>> start_end_list array([[2, 4], [6, 9]]) >>> example_array[start_end_list[0, 0] : start_end_list[0, 1]] array([1, 1])