Using the example below, how can I pull the max and min values marked as 'Top' and 'Bottom' into a separate array?
# Load library
import numpy as np
from findpeaks import findpeaks
# Data
i = 10000
xs = np.linspace(0,3.7*np.pi,i)
X = (0.3*np.sin(xs) + np.sin(1.3 * xs) + 0.9 * np.sin(4.2 * xs) + 0.06 * np.random.randn(i))
# Initialize
fp = findpeaks(method='peakdetect')
results = fp.fit(X)
# Plot
fp.plot1d()
I assume you're using the findpeaks library 2.4.0. The results
variable already contains the min
and max
value. You can get it as follows:
df_interp = results["df"]
min_peaks = df_interp["x"].loc[df_interp["valley"]].values
max_peaks = df_interp["x"].loc[df_interp["peak"]].values
print("min", min_peaks)
print("max", max_peaks)