code: def _merge_close(dat, events, time, min_interval):
      
      if not events.any():
          return events
      
      no_merge = time[events[1:, 0] - 1] - time[events[:-1, 2]] >= min_interval
  
      if no_merge.any():
          begs = concatenate([[events[0, 0]], events[1:, 0][no_merge]])
          ends = concatenate([events[:-1, 2][no_merge], [events[-1, 2]]])
  
          new_events = vstack((begs, ends)).T
      else:
          new_events = asarray([[events[0, 0], events[-1, 2]]])
  
      # add the location of the peak in the middle
      new_events = insert(new_events, 1, 0, axis=1)
      for i in new_events:
          if i[2] - i[0] >= 1:
              i[1] = i[0] + argmax(dat[i[0]:i[2]])
  
      return new_events
docs: Merge together events separated by less than a minimum interval.
  
      Parameters
      ----------
      dat : ndarray (dtype='float')
          vector with the data after selection-transformation
      events : ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples
      time : ndarray (dtype='float')
          vector with time points
      min_interval : float
          minimum delay between consecutive events, in seconds
  
      Returns
      -------
      ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples