numpy.correlate

numpy.correlate(a, v, mode='valid', old_behavior=False)[source]

Cross-correlation of two 1-dimensional sequences.

This function computes the correlation as generally defined in signal processing texts:

z[k] = sum_n a[n] * conj(v[n+k])

with a and v sequences being zero-padded where necessary and conj being the conjugate.

Parameters :

a, v : array_like

Input sequences.

mode : {‘valid’, ‘same’, ‘full’}, optional

Refer to the convolve docstring. Note that the default is valid, unlike convolve, which uses full.

old_behavior : bool

If True, uses the old behavior from Numeric, (correlate(a,v) == correlate(v,a), and the conjugate is not taken for complex arrays). If False, uses the conventional signal processing definition.

See also

convolve
Discrete, linear convolution of two one-dimensional sequences.

Examples

>>> np.correlate([1, 2, 3], [0, 1, 0.5])
array([ 3.5])
>>> np.correlate([1, 2, 3], [0, 1, 0.5], "same")
array([ 2. ,  3.5,  3. ])
>>> np.correlate([1, 2, 3], [0, 1, 0.5], "full")
array([ 0.5,  2. ,  3.5,  3. ,  0. ])

Previous topic

numpy.corrcoef

Next topic

numpy.cov

This Page