Find local maximums in numpy array

后端 未结 4 1042
抹茶落季
抹茶落季 2021-01-04 21:27

I am looking to find the peaks in some gaussian smoothed data that I have. I have looked at some of the peak detection methods available but they require an input range over

4条回答
  •  独厮守ぢ
    2021-01-04 21:37

    >> import numpy as np
    >> from scipy.signal import argrelextrema
    >> a = np.array([1,2,3,4,5,4,3,2,1,2,3,2,1,2,3,4,5,6,5,4,3,2,1])
    >> argrelextrema(a, np.greater)
    array([ 4, 10, 17]),)
    >> a[argrelextrema(a, np.greater)]
    array([5, 3, 6])
    

    If your input represents a noisy distribution, you can try smoothing it with NumPy convolve function.

提交回复
热议问题