• np.convolve


    Parameters:

     

    a : (N,) array_like

    First one-dimensional input array.

    v : (M,) array_like

    Second one-dimensional input array.

    mode : {‘full’, ‘valid’, ‘same’}, optional

    ‘full’:

    By default, mode is ‘full’. This returns the convolution at each point of overlap, with an output shape of (N+M-1,). At the end-points of the convolution, the signals do not overlap completely, and boundary effects may be seen.

    ‘same’:

    Mode ‘same’ returns output of length max(M, N). Boundary effects are still visible.

    ‘valid’:

    Mode ‘valid’ returns output of length max(M, N) - min(M, N) + 1. The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.

    Returns:

    out : ndarray

    Discrete, linear convolution of a and v.

    >>> N=3
    >>> weights = np.ones(N) / N
    >>> weights
    array([ 0.33333333,  0.33333333,  0.33333333])
    
    >>> c=[2,3,5]
    >>> np.convolve(weights, c)
    array([ 0.66666667,  1.66666667,  3.33333333,  2.66666667,  1.66666667])
    
    >>> np.convolve(weights, c,'same')
    array([ 1.66666667,  3.33333333,  2.66666667])
    
    >>> np.convolve(weights, c,'valid')
    array([ 3.33333333])
    
    >>> c=[2,3,6,2,7,9,10]
    
    >>> np.convolve(weights, c)
    array([ 0.66666667,  1.66666667,  3.66666667,  3.66666667,  5.        ,
            6.        ,  8.66666667,  6.33333333,  3.33333333])
    
    >>> np.convolve(weights, c,'same')
    array([ 1.66666667,  3.66666667,  3.66666667,  5.        ,  6.        ,
            8.66666667,  6.33333333])
    
    >>> np.convolve(weights, c,'valid')
    array([ 3.66666667,  3.66666667,  5.        ,  6.        ,  8.66666667])
    

     多用于计算移动平均,参数的不同之处在于边界的处理。

  • 相关阅读:
    面向对象第三单元博客作业
    面向对象编程第2次总结(电梯作业)
    面向对象编程第1次总结
    OOP 第四章博客总结
    OO 第三章总结
    OOP 第二章作业总结
    Java 设计模式 -- 代理模式
    ASID 与 MIPS 中 TLB 相关
    Java 锁机制总结
    OOP 第一章作业总结
  • 原文地址:https://www.cnblogs.com/nicolexu/p/5960757.html
Copyright © 2020-2023  润新知