I have a numpy array like this:
import numpy as np arr = np.array([9, 6, 3, 8, 2, 3, 3, 4, 4, 9, 5, 6, 6, 6, 6, 7, 8, 9])
And I want to get
Might not be the fastes but a oneliner with numpy would be:
index_dict = {v: np.flatnonzero(arr == v) for v in np.unique(arr)}