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])

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

posted on 2016-10-14 15:44  徐大猫  阅读(1084)  评论(0编辑  收藏  举报

导航