`np.arange(len(inverse))[array == array[k]])` is equivalent to `np.flatnonzero(array == array[k])` if I'm not mistaken.