在一维 numpy 数组中使用 Numpy 查找局部最大值/最小值 [英] Finding local maxima/minima with Numpy in a 1D numpy array

查看:64
本文介绍了在一维 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.

推荐答案

如果您要查找一维数组 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆