Short answer: Probably argrelextrema will not be flexible enough for your task. Think about how to write your own function that suits your needs.
Longer answer: Do you use argrelextrema ? If so, then you can play with the comparator and order argrelextrema (see reference ).
For your simple example, it would be enough to select np.greater_equal as comparator .
>>> data = np.array([ 0, 1, 2, 1, 0, 1, 3, 3, 1, 0 ]) >>> print(argrelextrema(data, np.greater_equal,order=1)) (array([2, 6, 7]),)
Please note that this way
>>> data = np.array([ 0, 1, 2, 1, 0, 1, 3, 3, 4, 1, 0 ]) >>> print(argrelextrema(data, np.greater_equal,order=1)) (array([2, 6, 8]),)
behaves differently, which you'll probably enjoy finding the first 3 and 4 as highs, since argrelextrema now sees everything as a maximum that is greater than or equal to its two closest neighbors. Now you can use the order argument to decide how many neighbors this comparison should take by choosing order=2 to change my top example to find a maximum of 4 .
>>> print(argrelextrema(data, np.greater_equal,order=2)) (array([2, 8]),)
However, there is a drawback - let it change the data again:
>>> data = np.array([ 0, 1, 2, 1, 0, 1, 3, 3, 4, 1, 5 ]) >>> print(argrelextrema(data, np.greater_equal,order=2)) (array([ 2, 10]),)
Adding another peak as the last value does not allow finding a peak at 4 , since argrelextrema now sees a second neighbor that is greater than 4 (which may be useful for noisy data, but not necessarily the behavior expected in all cases).
Using argrelextrema , you will always be limited to binary operations between a fixed number of neighbors. Note, however, that everything argrelextrema does in your example above returns n if data[n] > data[n-1] and data[n] > data[n+1] . You can easily implement this yourself, and then clarify the rules, for example, by checking the second neighbor in case the first neighbor has the same value.
For completeness, it seems to be a more complicated function in scipy.signal , find_peaks_cwt . However, I have no experience using it and therefore I can not give you more detailed information about this.