import numpy as np np.unique([1,6,6,2,2,3,4,5,5,5], return_index=True) >>> (array([1, 2, 3, 4, 5, 6]), array([0, 3, 5, 6, 7, 1], dtype=int64))