My program counts the number of times 3 different values โโappear and saves them in a list like this classes = [class1,class2,class3]
I want to return the index of the largest value, but these values โโwill often duplicate. If so, I want to return a randomly selected index between the largest values.
For example, if I have classes = [5,2,5]
, I want to print either 0 or 2. If I have classes = [1,1,1]
, then 0,1 and 2 are exact. Finally, if I have classes = [1,10,1]
, I want to output 1.
So far I have compiled this from other questions, but it does not behave the way I want, and I do not understand why.
classes = [class1,class2,class3]
dupes = [n for n, x in enumerate(classes) if x in classes[:n]]
class_prediction = dupes[random.randint(0,len(dupes))] + 1
(+1 at the end is to return the actual class label instead of the index.)