Finding local maxima/minima with Numpy in a 1D numpy array

后端 未结 12 1738
迷失自我
迷失自我 2020-11-22 15:13

Can you suggest a module function from numpy/scipy that can find local maxima/minima in a 1D numpy array? Obviously the simplest approach ever is to have a look at the neare

12条回答
  •  悲哀的现实
    2020-11-22 15:34

    If you are looking for all entries in the 1d array a smaller than their neighbors, you can try

    numpy.r_[True, a[1:] < a[:-1]] & numpy.r_[a[:-1] < a[1:], True]
    

    You could also smooth your array before this step using numpy.convolve().

    I don't think there is a dedicated function for this.

提交回复
热议问题