mel - 9 months ago 21

Python Question

I have a numpy array and I wan to have the index of the top value sorted that are superior to 0 for instance:

`[-0.4, 0.6, 0, 0, 0.4, 0.2, 0.7]`

And I want to have:

`[6, 1, 4, 5]`

I can do it using a function I implemented but I guess for this kind of task there is something already implemented in Numpy.

Answer

You can also do:

```
L = [-0.4, 0.6, 0, 0, 0.4, 0.2, 0.7]
[L.index(i) for i in sorted(filter(lambda x: x>0, L), reverse=True)]
Out[72]: [6, 1, 4, 5]
```