I have a list of float values (positive and negative ones) stored in a variable row of type <type 'numpy.ndarray'>.
max_value = max(row)
gives me the maximal value of row. Is there an elegant way to select the top 3 (5, 10,…) values?
I came up with
- selecting the maximum value from
row - deleting the maximal value in
row - selecting the maximum value from
row - deleting the maximal value in
row - and so on
But that’s certainly an ugly style and not pythonic at all. What do the pythonistas say to that? 🙂
Edit
I need not only the maximal three values, bit there position (index in row), too. Sorry, I forgot to mention that…
I would use
np.argsortEDIT
To also get the position, just use: