[Numpy-discussion] convolve
Robert Kern
rkern at ucsd.edu
Wed Jul 27 13:44:20 EDT 2005
Alan G Isaac wrote:
> On Wed, 27 Jul 2005, René Bastian apparently wrote:
>
>>Outcommenting
>>if len(data) < len(kernel):
>> data, kernel = kernel, data
>>in convolve.py gives the correct result.
>
> The author is not listed for this numarray module,
> so we cannot directly ask why this behavior was chosen.
This behavior was chosen for performance reasons. Since convolution is
commutative, it doesn't matter what order the arguments come in. I do
not see the behavior René is claiming. Perhaps René can tell us what
version of numarray he is using? or provide an example? I am using CVS
as of a week ago, I think.
In [10]: import numarray
In [11]: import numarray.convolve
In [12]: a = numarray.arange(10) + 1.
In [13]: b = numarray.arange(5) + 2.
In [14]: c = a - 1.
In [15]: numarray.convolve.convolve(a,b)
Out[15]:
array([ 2., 7., 16., 30., 50., 70., 90., 110., 130.,
150., 148., 133., 104., 60.])
In [16]: numarray.convolve.convolve(b,a)
Out[16]:
array([ 2., 7., 16., 30., 50., 70., 90., 110., 130.,
150., 148., 133., 104., 60.])
In [17]: numarray.convolve.convolve(a,c)
Out[17]:
array([ 0., 1., 4., 10., 20., 35., 56., 84., 120.,
165., 210., 244., 266., 275., 270., 250., 214., 161.,
90.])
In [18]: numarray.convolve.convolve(c,a)
Out[18]:
array([ 0., 1., 4., 10., 20., 35., 56., 84., 120.,
165., 210., 244., 266., 275., 270., 250., 214., 161.,
90.])
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the NumPy-Discussion
mailing list