Try getting local maximas and/or local minimas:
(尝试获取局部最大值和/或局部最小值:)
import numpy as np
from scipy.signal import argrelextrema
a = np.array([3,2,1,3])
res=a[np.hstack([argrelextrema(a, np.greater),argrelextrema(a, np.less)]).ravel()]
This will return both local maximas and minimas.
(这将同时返回局部最大值和最小值。)
You can mark them somehow separately, if it's better for your use case. (如果对您的用例更好,则可以单独标记它们。)
From your question I assumed it can be just one extremum. (根据您的问题,我认为这可能只是一个极值。)
Also - depending on your data you might consider using np.less_equal
or np.greater_equal
instead of np.less
or np.greater
respectively. (另外-根据您的数据,您可能会考虑分别使用np.less_equal
或np.greater_equal
而不是np.less
或np.greater
。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…