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_likeAn N-dimensional input array.
kernel_size: array_like, optionalA scalar or an N-length list giving the size of the median filter window in each dimension. Elements of
kernel_sizeshould be odd. Ifkernel_sizeis a scalar, then this scalar is used as the size in each dimension. Default size is 3 for each dimension.
Returns
out: ndarrayAn array the same size as input containing the median filtered result.
Warns
: UserWarningIf 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])✓
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
Aliases
scipy.signal.medfilt