I have two lists that have the same amount of elements. Each element is a number (float). I need to find the 10 greatest values in the first list, then find those values in the second list that have the same indices as the indices of the 10 greatest values in the first list. How can I do that? (I want to use numpy if possible). For instance:
a= [0.5, 2.9, 9.7]
b= [1, 3, 5.8]
I need the 2 greatest values from list a, which are 2.9 and 9.7. Their indices are 1 and 2, and so I need 3 and 5.8 from list b.
I haven't tried anything yet, I thought about amax or something, but I don't know.
Assuming this example (integers here for clarity, but this works identically with floats)
You can find the indices of the top 10 values with
numpy.argpartition, then index your second array:If you want them in order:
updated example:
pure python approach