scipy.signal.convolve computes the discrete linear convolution of two same-dimensional array-like inputs. Choose full, same, or valid to control the output region, and choose direct, fft, or the default auto to control how SciPy computes it. For inputs containing NaN or Inf, use method='direct': FFT convolution can spread non-finite values across the output.
How to convolve two arrays in SciPy
Import the function from scipy.signal and pass the two inputs. This example smooths a square pulse with a Hann window, following SciPy’s documented example:
import numpy as np
from scipy import signal
sig = np.repeat([0., 1., 0.], 100)
win = signal.windows.hann(51)
smoothed = signal.convolve(sig, win, mode="same") / win.sum()
The division by the window sum normalizes the smoothing result. With mode="same", the result has the shape of sig; near the edges, the result reflects the convolution’s zero-padding assumptions rather than data beyond the ends of the signal. See the SciPy convolve API reference.
What the function computes
For N-dimensional inputs, convolve computes their discrete linear convolution. Both inputs must have the same number of dimensions; their lengths can differ. For an axis where the input lengths are N and M, the full convolution has length N + M − 1. The operation is commonly used to combine finite signals or apply a kernel to an array.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
Choose the output mode
The mode argument controls which part of the full convolution is returned. It changes the result’s region and shape, not the algorithm used to compute it.
| Mode | What it returns | Shape along an axis with input lengths N and M |
|---|---|---|
full (default) |
The entire linear convolution, including values at the edges where the inputs overlap only partly. | N + M − 1 |
same |
A centered section of the full result with the shape of the first input, in1. Edge values can reflect boundary effects. |
Length of in1 |
valid |
Only values that do not rely on zero padding. One input must be at least as large as the other in every dimension. | max(N, M) − min(N, M) + 1 |
Use full when you need the complete finite convolution, same when you need an output aligned to the first input’s shape, and valid when you want to exclude partial-overlap results. The required size relationship for valid applies on every axis.
Rank #2
Choose how SciPy computes the convolution
The method argument is separate from mode: it selects the computation strategy, not the output shape.
directevaluates the convolution from sums. It can be appropriate for smaller inputs and is the recommended choice when inputs contain NaN or Inf.fftcomputes convolution using the Fourier transform, throughfftconvolve. FFT-based computation can be more efficient for larger inputs, but the crossover depends on the workload.auto(default) estimates which method is faster for the given inputs. It is a selection estimate, not a guarantee that one method will win for every workload.
For one-dimensional inputs, the broad complexity comparison is O(N²) for direct convolution and O(N log N) for FFT convolution. Those growth rates do not by themselves determine which is faster on real inputs: sizes and implementation costs matter. If runtime is important, benchmark both methods with representative input shapes and data on the system where the code will run. SciPy’s signal-processing tutorial discusses convolution methods and their trade-offs.
NaN and Inf: use the direct method
SciPy warns that FFT convolution with NaN or Inf values can produce an output in which the entire result is NaN or Inf. If either input contains non-finite values, specify method="direct" rather than relying on the default method selection. This avoids the documented FFT propagation issue; it does not decide how your application should handle missing data.
When a related SciPy function is a better fit
scipy.signal.convolve is a general choice for N-dimensional linear convolution with its full, same, and valid output regions. If the task depends on a particular boundary rule, compare it with these alternatives:
scipy.signal.convolve2dis for 2-D signal convolution and offers explicitfill,wrap, andsymmboundary behavior. SciPy’s convolve2d reference demonstrates a Scharr image-gradient calculation using symmetric boundaries.scipy.ndimage.convolveis suited to array and image filtering with boundary-extension choices includingreflect,constant,nearest,mirror, andwrap; its default boundary mode isreflect. See the ndimage convolve reference.scipy.signal.oaconvolveuses overlap-add, which the API reference describes as generally useful when arrays are large and significantly different in size.scipy.signal.fftconvolveselects FFT-based convolution directly, whilescipy.signal.choose_conv_methodlets you inspect SciPy’s method choice; both are listed in the convolve API reference.
Version and backend considerations
The linked API reference identifies itself as SciPy v1.18.0. Documentation and behavior can change across versions, so check the installed SciPy version if a detail matters to a particular runtime. The reference marks Array API backend support as experimental, with capabilities varying by backend and device; do not assume every backend or device supports the same behavior.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.




