def groupify(values):
    group = np.zeros((len(values[0]),), dtype=np.int64) - 1
next_hash = 0
matching = np.ones((len(values[0]),), dtype=bool)
while any(group == -1):
    matching[:] = group == -1
first_ungrouped_idx = np.where(matching)[0][0]
for curr_id, value_array in enumerate(values):
    needed_value = value_array[first_ungrouped_idx]
matching[matching] = value_array[matching] == needed_value
group[matching] = next_hash
next_hash += 1
return group

def groupify_vectorized(values):
    arr = np.vstack(values)
idx = np.ravel_multi_index(arr, arr.max(1) + 1)
_, unq_start_idx, unqID, count = np.unique(idx, return_index=True,
    return_inverse=True, return_counts=True)
mask = ~np.in1d(unqID, np.where(count > 1)[0])
mask[unq_start_idx] = 1
return idx[mask].argsort()[unqID]
Fast algorithm to find indices where multiple arrays have the same value