I have two array
my_arr
distances
my_arr= np.array([0, 1, 3, 4, 5, 3, 5])
distances = np.array([18, 47, 20, 10, 26, 22, 13])
np.unique(my_arr).size
# indices of my_arr
indices_of_my_arr= np.array([0, 1, 2, 3, 6])
for
map
my_arr = np.array([0, 2, 3, 1, 3, 4, 4, 5])
dist = np.array([10, 12, 15, 18, 5, 14, 45, 8])
[0, 1, 3, 4, 5, 7]
You can use np.lexsort
and np.unique

idx = np.lexsort([distances, my_arr])
out = np.sort(idx[np.unique(my_arr[idx], return_index=1)[1]])