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
You can use numpy.unique to find all the unique values and numpy.where to find their indexes:
import numpy as np
arr = np.array([2, 3, 3, 4, 4, 9, 5, 6, 6, 6, 6, 7, 8, 9])
# get the unique values
unique_arr = np.unique(arr)
# loop through the unique numbers and find the indeces
indexes_value = {}
for num in unique_arr:
indexes = np.where(arr == num)[0]
indexes_value[num] = indexes # or list(indexes) if you prefer
Now you have a dictionary of indexes of each value and you can assign what you want to your index_list_*
lists.