I added code for a simple example below which finds all local minima and all local maxima of an array and stores them in minVal
and maxVal
, respectively. Please note: When you apply this to large datasets, make sure to smooth the signals first; otherwise you will end up with tons of extrema.
The data looks as follows; the calculated minima/maxima are at [2, 5, 7]
and [1, 3, 6]
, respectively:

Here is the code:
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt
X=np.arange(9)
Y=np.array([ 3, 5, 1, 9, 3, 2, 10, 7, 8])
plt.plot(X,Y)
plt.show()
maxVal = argrelextrema(Y, np.greater) #(array([1, 3, 6]),)
minVal = argrelextrema(Y, np.less) #(array([2, 5, 7]),)