finding index of greatest element comparison in numpy array

arrays, max, numpy, python

Solution

You can slice the array and find the maximum yourself and then query its index:

np.where(a==a[a<v].max())
Out: (array([3]),)

Problem

I have an array `a` and I want to find the position of largest element in `a` that a given value is still greater than. In this example: ``` a = np.array([0, 50, 5, 52, 60]) v = 55 ``` the greatest element that `v` is bigger than is `52` (index 3) so I want to return 3. The numpy function `argmax()` doesn't work for this purpose since it returns the first element. What is the fast and correct way to do this with numpy?

Original source