Skip to content
Advertisement

Find the first and last element of a NumPy array larger than a threshold

I need to find the first and the last element of a numpy.ndarray which are above a specified threshold. I found the following solution, which works, but it looks a bit convoluted. Is there a simpler/more Pythonic way?

JavaScript

Advertisement

Answer

You could just access the first/last elements

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement