[Numpy-discussion] Problem with correlate?

Hanno Klemm klemm at phys.ethz.ch
Wed Aug 20 08:13:21 EDT 2008


Hi All,

after the discussion on numpy.correlate some time ago, regarding
complex conjugation, etc. I today was pointed to yet another oddity,
which I hope somebody could explain to me, as to why that's a feature,
rather than a bug. I'm thoroughly confused by the following behaviour: 
 

In [29]: x = array([0.,0.,1, 0, 0])

In [30]: y = array([0, 0, 0, 1., 0, 0, 0])

In [31]: correlate(x,y)
Out[31]: array([ 0.,  1.,  0.])

In [32]: correlate(x,y, mode='full')
Out[32]: array([ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.])

In [33]: y = array([0,0,1.,0,0])

In [34]: correlate(x,y,mode='full')
Out[34]: array([ 0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.])

So far, everything is allright and as expected. Now:

In [35]: y1 = array([1,0,0,0,0])

In [36]: correlate(x,y1,mode='full')
Out[36]: array([ 0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.])

In [37]: y2 = array([1,0,0,0,0,0,0])

In [38]: correlate(x,y2,mode='full')
Out[38]: array([ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

Could somebody please help me understanding, why the one switches
places? Furthermore, this behaviour does not seem to be very
consistent, if we switch the x and y argument:

In [39]: correlate(y2,x,mode='full')
Out[39]: array([ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

In [40]: correlate(y1,x,mode='full')
Out[40]: array([ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.])

The answer remains the same. Any help would be appreciated, the numpy
version is 1.0.4.

Best regards,
Hanno




-- 
Hanno Klemm
klemm at phys.ethz.ch





More information about the NumPy-Discussion mailing list