找出曲线中的所有最小值

时间:2019-06-07 12:26:55

标签: python scipy

我需要找出曲线上的所有最小值,但我只是局部最小值。

counts = np.sum(chunked_images[2]<chunked_images[2].max()/2., axis=1)

N = 15

cumsum, moving_aves = [0], []

for i, x in enumerate(counts, 1):    
    cumsum.append(cumsum[i-1] + x)

    if i>=N:
        moving_ave = (cumsum[i] - cumsum[i-N])/N
        #can do stuff with moving_ave here
        moving_aves.append(moving_ave)

moving_aves = np.array(moving_aves)
a = argrelextrema(moving_aves, np.less)
print(a)

结果:(array([611, 628, 651]),) 但这不是最低要求:

img

1 个答案:

答案 0 :(得分:0)

最好的方法是应用局部最小值的定义。

i的索引counts是局部最小值:

counts[i-1] > counts[i] and counts[i+1] > counts[i]