Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

signal.correlate

Computes the discrete linear cross-correlation of two N-dimensional arrays. The mode selects the output region, and method selects direct, FFT, or automatic computation.

How it works

signal.correlate computes the discrete linear cross-correlation of two N-dimensional arrays. It selects the output region with mode and uses either direct summation, an FFT-based method, or an automatic choice based on an estimated cost.

Syntax

scipy.signal.correlate(in1, in2, mode='full', method='auto')

Parameters

NameTypeDescription
in1array_likeFirst input array.
in2array_likeSecond input; it must have the same number of dimensions as in1.
mode{'full', 'valid', 'same'}, optionalOutput selection: full, valid, or same; defaults to full.
method{'auto', 'direct', 'fft'}, optionalComputation strategy: direct, fft, or auto; defaults to auto.

Returns

An N-dimensional array containing a subset of the discrete linear cross-correlation of in1 with in2.

Key points

  • The function accepts two N-dimensional inputs, and mode determines the size of the returned region.
  • full mode retains the complete discrete linear cross-correlation.
  • valid mode keeps only results independent of zero-padding.
  • same mode produces an output shaped like in1 and centered against the full result.
  • direct computes correlation through the defining summations.
  • fft accelerates correlation with a Fast Fourier Transform when its input types permit it.
  • auto selects direct or FFT processing using an estimated speed comparison and is the default.

Common mistakes

  • For valid mode, one input must be at least as large as the other along every dimension.

Example: Full cross-correlation

import numpy as np
from scipy import signal

x = np.array([1, 2, 3])
template = np.array([1, 1])
result = signal.correlate(x, template, mode="full")
print(result)

Computes the full cross-correlation sequence between two one-dimensional numeric arrays.

When to use it

Template matching

Compare a measured signal with a reference waveform to locate matching delays.

Lag analysis

Measure similarity between sequences as one is shifted relative to the other.

N-dimensional signal comparison

Process multidimensional numerical data where alignment or similarity across offsets matters.

Interview questions

QWhat does signal.correlate compute?

It cross-correlates two N-dimensional arrays and returns an array containing a subset of their discrete linear cross-correlation. The mode controls the output region, while method controls how the computation is performed.

Follow-up: When is fft unsuitable? It is available only for numerical arrays, so non-numeric inputs require direct computation.

QHow do the mode choices differ?

full returns the complete discrete linear cross-correlation. same returns an output shaped like in1 and centered relative to the full result, while valid excludes values that depend on zero-padding.

Follow-up: What restriction applies to valid? Either input must be at least as large as the other in every dimension.

QHow does method affect execution?

direct evaluates the correlation from sums, fft uses the Fast Fourier Transform, and auto estimates which of those approaches is faster; auto is the default.

Follow-up: What practical limitation does fft have? It is available only for numerical arrays.

  • scipy.signal.convolve
  • scipy.signal.fftconvolve
  • scipy.signal.correlate2d
  • scipy.signal.correlation_lags

Source: scipy.signal.correlate. Checked 2026-10-15.