def merge_events(events, ids, new_id, replace_events=True):
 events = np.asarray(events)
 events_out = events.copy()
 idx_touched = []
 for col in [1, 2]:
  for i in ids:
   mask = (events[:, col] == i)
   events_out[(mask, col)] = new_id
   idx_touched.append(np.where(mask)[0])
 if (not replace_events):
  idx_touched = np.unique(np.concatenate(idx_touched))
  events_out = np.concatenate((events_out, events[idx_touched]), axis=0)
  events_out = events_out[np.lexsort(events_out.T[::(-1)])]
 return events_out

def merge_events ( events , ids , new_id , replace_events = True ) : events = np . asarray ( events ) events_out = events . copy ( ) idx_touched = [ ] for col in [ 1 , 2 ] : for i in ids : mask = ( events [ : , col ] == i ) events_out [ ( mask , col ) ] = new_id idx_touched . append ( np . where ( mask ) [ 0 ] ) if ( not replace_events ) : idx_touched = np . unique ( np . concatenate ( idx_touched ) ) events_out = np . concatenate ( ( events_out , events [ idx_touched ] ) , axis = 0 ) events_out = events_out [ np . lexsort ( events_out . T [ : : ( - 1 ) ] ) ] return events_out
merge a set of events .