code: def _remove_duplicate(old_events, dat):
      
      diff_events = diff(old_events, axis=0)
      dupl = where((diff_events[:, 0] == 0) & (diff_events[:, 2] == 0))[0]
      dupl += 1  # more convenient, it copies old_event first and then compares
  
      n_nondupl_events = old_events.shape[0] - len(dupl)
      new_events = zeros((n_nondupl_events, old_events.shape[1]), dtype='int')
      if len(dupl):
          lg.debug('Removing ' + str(len(dupl)) + ' duplicate events')
  
      i = 0
      indices = []
      for i_old, one_old_event in enumerate(old_events):
          if i_old not in dupl:
              new_events[i, :] = one_old_event
              i += 1
              indices.append(i_old)
          else:
              peak_0 = new_events[i - 1, 1]
              peak_1 = one_old_event[1]
              if dat[peak_0] >= dat[peak_1]:
                  new_events[i - 1, 1] = peak_0
              else:
                  new_events[i - 1, 1] = peak_1
  
      return indices, new_events
docs: Remove duplicates from the events.
  
      Parameters
      ----------
      old_events : ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples
      dat : ndarray (dtype='float')
          vector with the data after detection-transformation (to compute peak)
  
      Returns
      -------
      ndarray (dtype='int')
          vector of indices of the events to keep
      ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples
  
      Notes
      -----
      old_events is assumed to be sorted. It only checks for the start time and
      end time. When two (or more) events have the same start time and the same
      end time, then it takes the largest peak.
  
      There is no tolerance, indices need to be identical.