Skip to content

Instantly share code, notes, and snippets.

@Multihuntr
Created August 2, 2019 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Multihuntr/a1c5105b55e712847f798026da6e9793 to your computer and use it in GitHub Desktop.
Save Multihuntr/a1c5105b55e712847f798026da6e9793 to your computer and use it in GitHub Desktop.
Numpy gaussian smoothing
# Super simple 1D smoothing with just numpy. Just smooths a few sharp edges.
import math
import numpy as np
def gaussian_kernel(n=5):
x = np.arange(n)/n
g = math.e ** -(x**2/((n - 2)**2)) # drop the constant factor at the start
return g/g.sum() # normalise so it sums to 1
def gaussian_smooth(x, n=5, passes=2):
for x in range(passes):
x = np.convolve(x, gaussian_kernel(n))
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment