[Numpy-discussion] Bug in numpy.correlate documentation
Bernhard Spinnler
Bernhard.Spinnler at gmx.net
Mon Oct 7 17:09:41 EDT 2013
The numpy.correlate documentation says:
correlate(a, v) = z[k] = sum_n a[n] * conj(v[n+k])
In [1]: a = [1, 2]
In [2]: v = [2, 1j]
In [3]: z = correlate(a, v, 'full')
In [4]: z
Out[4]: array([ 0.-1.j, 2.-2.j, 4.+0.j])
However, according to the documentation, z should be
z[-1] = a[1] * conj(v[0]) = 4.+0.j
z[0] = a[0] * conj(v[0]) + a[1] * conj(v[1]) = 2.-2.j
z[1] = a[0] * conj(v[1]) = 0.-1.j
which is the time reversed version of what correlate() calculates.
IMHO, the correlate() code is correct. The correct formula in the docs (which is also the correlation formula in standard text books) should be
z[k] = sum_n a[n+k] * conj(v[n])
Cheers,
Bernhard
More information about the NumPy-Discussion
mailing list