numpy.convolve(a,v,mode='full')[source]¶Returns the discrete, linear convolution of two one-dimensional sequences.
The convolution operator is often seen in signal processing, where itmodels the effect of a linear time-invariant system on a signal[1]. Inprobability theory, the sum of two independent random variables isdistributed according to the convolution of their individualdistributions.
Ifv is longer thana, the arrays are swapped before computation.
| Parameters: |
|
|---|---|
| Returns: |
|
See also
scipy.signal.fftconvolvescipy.linalg.toeplitzpolymulNotes
The discrete convolution operation is defined as
(a * v)[n] = \sum_{m = -\infty}^{\infty} a[m] v[n - m]
It can be shown that a convolutionx(t) * y(t) in time/spaceis equivalent to the multiplicationX(f) Y(f) in the Fourierdomain, after appropriate padding (padding is necessary to preventcircular convolution). Since multiplication is more efficient (faster)than convolution, the functionscipy.signal.fftconvolve exploits theFFT to calculate the convolution of large data-sets.
References
| [1] | (1,2) Wikipedia, “Convolution”,http://en.wikipedia.org/wiki/Convolution. |
Examples
Note how the convolution operator flips the second arraybefore “sliding” the two across one another:
>>>np.convolve([1,2,3],[0,1,0.5])array([ 0. , 1. , 2.5, 4. , 1.5])
Only return the middle values of the convolution.Contains boundary effects, where zeros are takeninto account:
>>>np.convolve([1,2,3],[0,1,0.5],'same')array([ 1. , 2.5, 4. ])
The two arrays are of the same length, so thereis only one position where they completely overlap:
>>>np.convolve([1,2,3],[0,1,0.5],'valid')array([ 2.5])