This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / signal / _signaltools / medfilt

function

scipy.signal._signaltools:medfilt

source: build-install/usr/lib/python3.14/site-packages/scipy/signal/_signaltools.py:1618

Signature

def medfilt(volume, kernel_size = None)

Summary

Perform a median filter on an N-dimensional array.

Extended Summary

Apply a median filter to the input array using a local window-size given by kernel_size. The array will automatically be zero-padded.

Parameters

volume : array_like

An N-dimensional input array.

kernel_size : array_like, optional

A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of kernel_size should be odd. If kernel_size is a scalar, then this scalar is used as the size in each dimension. Default size is 3 for each dimension.

Returns

out : ndarray

An array the same size as input containing the median filtered result.

Warns

: UserWarning

If array size is smaller than kernel size along any dimension

Examples

Apply a 1-D median filter to an array containing noise spikes.
import numpy as np
from scipy import signal
x = np.array([1, 2, 100, 2, 1, 1, 35, 30, 1])
✓
Apply a filter with a kernel size of 3:
signal.medfilt(x, kernel_size=3)
✓
array([ 1,  2,  2,  2,  1,  1, 30, 30,  1])
The size 3 kernel is not big enough to eliminate the 2-wide spike near the end of the array. A larger size 5 kernel successfully eliminates the 2-wide spike.
signal.medfilt(x, kernel_size=5)
✓
array([1, 2, 2, 2, 2, 2, 1, 1, 1])
Kernel size 1 acts as an identity operator.
signal.medfilt(x, kernel_size=1)
✓
array([  1,   2, 100,   2,   1,   1,  35,  30,   1])

See also

scipy.ndimage.median_filter
scipy.signal.medfilt2d

Aliases

  • scipy.signal.medfilt

Referenced by