Skip to content

Instantly share code, notes, and snippets.

@nickv2002
nickv2002 / mean_median_filters.py
Last active July 7, 2023 02:07 — forked from bhawkins/medfilt.py
1-Dimentional Mean and Median Filters
#!/usr/bin/env python
def medfilt (x, k):
"""Apply a length-k median filter to a 1D array x.
Boundaries are extended by repeating endpoints.
"""
import numpy as np
assert k % 2 == 1, "Median filter length must be odd."
assert x.ndim == 1, "Input must be one-dimensional."