Smoothing
Reduce high-frequency noise in images or multidimensional measurements.
SciPy · Function
Applies a multidimensional Gaussian filter to an array. It can smooth data, compute Gaussian derivatives, and control boundary handling and kernel size.
gaussian_filter smooths an array by applying Gaussian convolution independently along each selected axis. The sigma value controls the standard deviation of the kernel; order selects Gaussian derivatives, while mode, cval, truncate, and optional radius control boundaries and kernel extent.
scipy.ndimage.gaussian_filter(input, sigma, order=0, output=None, mode='reflect', cval=0.0, truncate=4.0, *, radius=None, axes=None)| Name | Type | Description |
|---|---|---|
input | array_like | Input array. |
sigma | scalar or sequence of scalars | Standard deviation of the Gaussian kernel; scalar or one value per axis. |
order | int or sequence of ints, optional | Filter order per axis; zero means Gaussian convolution and positive values mean Gaussian derivatives. |
output | array or dtype, optional | Destination array or dtype for the result. |
mode | str or sequence of str, optional | How array borders are handled. |
cval | scalar, optional | Value used beyond the borders when mode is constant. |
truncate | float, optional | Number of standard deviations at which to truncate the filter. |
radius | int or sequence of ints, optional | Explicit Gaussian-kernel radius; overrides truncate. |
axes | tuple of int, optional | Axes over which to apply the filter. |
ndarray: filtered array with the same shape as input.
import numpy as np
from scipy.ndimage import gaussian_filter
image = np.zeros((7, 7), dtype=float)
image[3, 3] = 1.0
blurred = gaussian_filter(image, sigma=1.0)
print(np.round(blurred, 3))Creates a 2D impulse and smooths it with an isotropic Gaussian filter.
Reduce high-frequency noise in images or multidimensional measurements.
Identify directional changes or edges using positive derivative orders.
Restrict processing to selected dimensions or explicitly control the kernel footprint.
It applies a multidimensional Gaussian filter by performing one-dimensional convolutions along the axes. With order=0 it performs Gaussian convolution; positive orders apply derivatives of the Gaussian.
Follow-up: How would you limit filtering to selected dimensions? Use axes to specify the dimensions, and provide compatible sigma, order, mode, or radius sequences for those axes.
sigma is the Gaussian kernel standard deviation. A scalar uses the same value on every filtered axis, while a sequence supplies one value per axis.
Follow-up: What changes when radius is set? The kernel width becomes 2*radius+1 per axis, and truncate is ignored.
output can be an array receiving the result or a dtype specifying the result type. If omitted, SciPy creates an array with the input dtype, and the returned array has the same shape as the input.
Follow-up: Why can this affect numeric quality? Intermediate arrays use the output dtype, so a narrow or integer dtype can make results imprecise.
scipy.ndimage.gaussian_filter1dscipy.ndimage.gaussian_gradient_magnitudescipy.ndimage.gaussian_laplacescipy.ndimage.convolve