I have a numpy array like that:
a = numpy.array([1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0])
The goal is to find the ranges of zeros and ones, start and end indices. I want to use this ranges in another numpy array which contains time stamps to find out how much time each zero phase takes. Something like that:
dur = numpy.diff(time[start idx, end idx])
However, numpy where gives me all indices:
numpy.where(a==0)
(array([ 3, 4, 5, 9, 10, 11], dtype=int64),)
I would need only start and end idx of each zero phase, like [[3,5],[9,11]]. How can I achieve that?