code: def _detect_start_end(true_values):
      
      neg = zeros((1), dtype='bool')
      int_values = asarray(concatenate((neg, true_values[:-1], neg)), 
                           dtype='int')
      # must discard last value to avoid axis out of bounds
      cross_threshold = diff(int_values)
  
      event_starts = where(cross_threshold == 1)[0]
      event_ends = where(cross_threshold == -1)[0]
  
      if len(event_starts):
          events = vstack((event_starts, event_ends)).T
  
      else:
          events = None
  
      return events
docs: From ndarray of bool values, return intervals of True values.
  
      Parameters
      ----------
      true_values : ndarray (dtype='bool')
          array with bool values
  
      Returns
      -------
      ndarray (dtype='int')
          N x 2 matrix with starting and ending times.