在一维numpy数组中用Numpy查找局部最大值/最小值 [英] Finding local maxima/minima with Numpy in a 1D numpy array
本文介绍了在一维numpy数组中用Numpy查找局部最大值/最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您能建议numpy/scipy中的模块函数在一维numpy数组中找到局部最大值/最小值吗?显然,最简单的方法是看一下最近的邻居,但我想拥有一个被接受的解决方案,它是numpy发行版的一部分.
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 nearest neighbours, but I would like to have an accepted solution that is part of the numpy distro.
推荐答案
如果要查找1d数组a
中小于其邻居的所有条目,则可以尝试
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]
在执行此步骤之前,您还可以使用numpy.convolve()
平滑阵列.
You could also smooth your array before this step using numpy.convolve()
.
我认为没有专门的功能.
I don't think there is a dedicated function for this.
这篇关于在一维numpy数组中用Numpy查找局部最大值/最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文