Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

SciPy’s Convolve Function: Modes, Methods, and Examples

SciPy’s signal.convolve computes N-dimensional linear convolution. Learn how to choose the output mode and computation method, and when to use related SciPy APIs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Choose how SciPy computes the convolution

The method argument is separate from mode: it selects the computation strategy, not the output shape.

  • direct evaluates the convolution from sums. It can be appropriate for smaller inputs and is the recommended choice when inputs contain NaN or Inf.
  • fft computes convolution using the Fourier transform, through fftconvolve. 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.convolve2d is for 2-D signal convolution and offers explicit fill, wrap, and symm boundary behavior. SciPy’s convolve2d reference demonstrates a Scharr image-gradient calculation using symmetric boundaries.
  • scipy.ndimage.convolve is suited to array and image filtering with boundary-extension choices including reflect, constant, nearest, mirror, and wrap; its default boundary mode is reflect. See the ndimage convolve reference.
  • scipy.signal.oaconvolve uses overlap-add, which the API reference describes as generally useful when arrays are large and significantly different in size.
  • scipy.signal.fftconvolve selects FFT-based convolution directly, while scipy.signal.choose_conv_method lets you inspect SciPy’s method choice; both are listed in the convolve API reference.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.