I\'m trying to get the index of all repeated elements in a numpy array, but the solution I found for the moment is REALLY inefficient for a large (>20000 elements) input
so I was unable to get rid of the for loop, but I was able to pair it down to using the for loop marginally using the set data type and the list.count() method:
data = [1,2,3,1,4,5,2,2]
indivs = set(data)
multi_index = lambda lst, val: [i for i, x in enumerate(lst) if x == val]
if data != list(indivs):
dupes = [multi_index(data, i) for i in indivs if data.count(i) > 1]
Where you loop over your indivs set, which contains the values (no duplicates) and then loop over the full list if you find an item with a duplicate. Am looking into numpy alternative if this isn't fast enough for you. Generator objects might also speed this up if need be.
Edit: gg349's answer holds the numpy solution I was working on!