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

SciPy · Function

signal.convolve

Convolve two N-dimensional arrays using selectable output sizing and computation methods. The result is a requested subset of their discrete linear convolution.

How it works

The function performs discrete linear convolution between two N-dimensional array-like inputs. Choose the output extent with mode, then choose direct, FFT-based, or automatic computation with method; the returned array contains the requested portion of the convolution.

Syntax

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

Parameters

NameTypeDescription
in1array_likeFirst input array-like.
in2array_likeSecond input array-like; it should have the same number of dimensions as in1.
modestr {‘full’, ‘valid’, ‘same’}, optionalOutput-size selector: full, valid, or same.
methodstr {‘auto’, ‘direct’, ‘fft’}, optionalConvolution algorithm selector: auto, direct, or fft.

Returns

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

Key points

  • Accepts two N-dimensional array-like inputs and computes their discrete linear convolution.
  • Output dimensions are determined independently by the selected mode.
  • full mode retains every position in the linear convolution.
  • valid mode keeps only positions unaffected by implicit zero-padding.
  • same mode matches the shape of the first input and centers the result.
  • method selects how SciPy calculates the convolution.
  • The result is an N-dimensional array containing the portion requested by mode.

Common mistakes

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

Example: Convolve a signal with a kernel

import numpy as np
from scipy.signal import convolve

signal = np.array([1, 2, 3])
kernel = np.array([1, 1])
result = convolve(signal, kernel, mode="same")
print(result)

Convolves a one-dimensional signal with a two-element kernel and returns an output matching the signal's shape.

When to use it

Signal filtering

Apply a finite impulse response or smoothing kernel to sampled data.

Array and image operations

Combine multidimensional arrays when the complete or cropped linear convolution is needed.

Performance-aware convolution

Use automatic algorithm selection for general-purpose convolution workloads.

Interview questions

QWhat does scipy.signal.convolve do?

It computes the discrete linear convolution of two N-dimensional array-like inputs. The mode argument controls whether the result is full, valid, or the same size as the first input.

Follow-up: How would you select the computation strategy? Use direct for straightforward computation, fft for FFT-based convolution, or auto to let SciPy choose.

QHow do the mode values differ?

full returns the complete discrete linear convolution. valid excludes values dependent on zero-padding and imposes a size relationship between the inputs; same returns an output shaped like in1 and centered relative to full.

Follow-up: What constraint matters for multidimensional valid convolution? One input must be at least as large as the other in every dimension.

QWhat does the method parameter control?

method selects the algorithm: direct uses the definition directly, fft uses FFT convolution, and auto estimates which is faster. The function returns an N-dimensional array containing the selected convolution subset.

Follow-up: What numerical caveat applies to FFT convolution? NaN or inf values can propagate through the FFT and generate NaN output, so direct computation may be safer for such inputs.

  • scipy.signal.fftconvolve
  • scipy.signal.oaconvolve
  • scipy.signal.correlate
  • scipy.signal.convolve2d

Source: scipy.signal.convolve — SciPy v1.16.2 Manual. Checked 2026-10-15.