Find local maximums in numpy array

后端 未结 4 1054
抹茶落季
抹茶落季 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:39

    If you can exclude maxima at the edges of the arrays you can always check if one elements is bigger than each of it's neighbors by checking:

    import numpy as np
    array = 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])
    # Check that it is bigger than either of it's neighbors exluding edges:
    max = (array[1:-1] > array[:-2]) & (array[1:-1] > array[2:])
    # Print these values
    print(array[1:-1][max])
    # Locations of the maxima
    print(np.arange(1, array.size-1)[max])
    

提交回复
热议问题