bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / correlate
_ArrayFunctionDispatcher
numpy:correlate
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/numeric.py :725
Signature
def correlate ( a , v , mode = valid ) Summary
Cross-correlation of two 1-dimensional sequences.
Extended Summary
This function computes the correlation as generally defined in signal processing texts [1]:
with a and v sequences being zero-padded where necessary and denoting complex conjugation.
Parameters
a, v: array_likeInput sequences.
mode: {'valid', 'same', 'full'}, optionalRefer to the
convolvedocstring. Note that the default is 'valid', unlikeconvolve, which uses 'full'.
Returns
out: ndarrayDiscrete cross-correlation of
aandv.
Notes
The definition of correlation above is not unique and sometimes correlation may be defined differently. Another common definition is [1]:
which is related to by .
numpy.correlate may perform slowly in large arrays (i.e. n = 1e5) because it does not use the FFT to compute the convolution; in that case, scipy.signal.correlate might be preferable.
Examples
import numpy as np np.correlate([1, 2, 3], [0, 1, 0.5])✓
np.correlate([1, 2, 3], [0, 1, 0.5], "same") np.correlate([1, 2, 3], [0, 1, 0.5], "full")✗
np.correlate([1+1j, 2, 3-1j], [0, 1, 0.5j], 'full')
✗np.correlate([0, 1, 0.5j], [1+1j, 2, 3-1j], 'full')
✗See also
- convolve
Discrete, linear convolution of two one-dimensional sequences.
- scipy.signal.correlate
uses FFT which has superior performance on large arrays.
Aliases
-
numpy.correlate