You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用scipy find_peaks检测数组峰值,返回结果疑为空峰值求技术指导

关于scipy.find_peaks返回结果的解释与优化建议

你误解了返回结果——这个结果不是空的:

  • 返回元组的第一个元素array([ 1, 5, 10], dtype=int64)就是检测到的峰值在原数组中的索引位置
  • 第二个空字典只是表示没有额外的峰属性(比如峰高、宽度),不代表未找到峰值

为什么这些索引被判定为峰值?

对应原数组的数值来看:

  • 索引1:84.643,比左右相邻的84.6345和84.6375都大,是局部峰值
  • 索引5:84.5345,左右相邻值为84.524和84.5305,确实是该局部区间的最高点
  • 索引10:84.668,是整个数组的全局峰值,左右值明显更低

如何过滤掉不需要的小峰值?

如果这些局部小峰值不符合你的预期,可以通过find_peaks的参数来过滤:

  • height:只保留高于指定阈值的峰值
    import numpy as np
    from scipy.signal import find_peaks
    
    Array = np.array([84.6345, 84.643, 84.6375, 84.568, 84.524, 84.5345, 84.5305, 84.548, 84.562, 84.6295, 84.668, 84.5795, 84.565, 84.5715])
    peaks, props = find_peaks(Array, height=84.6)
    print(peaks)  # 输出峰值索引:[1 10]
    print(props['peak_heights'])  # 输出对应峰值高度:[84.643 84.668]
    
  • distance:要求峰值之间的最小间隔(索引差),过滤近距离的小峰
    peaks, props = find_peaks(Array, distance=5)
    # 输出峰值索引:[1 10],去掉了间隔太近的索引5
    
  • prominence:根据峰的突出程度过滤,只保留“足够明显”的峰
    peaks, props = find_peaks(Array, prominence=0.05)
    # 输出峰值索引:[1 10],过滤掉突出度不足的索引5
    

内容的提问来源于stack exchange,提问作者joenpc npcsolution

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 22:48:35