Skip to content

Instantly share code, notes, and snippets.



Last active Jul 25, 2020
What would you like to do?
Fastest found numpy method of generating a gaussian kernel of size n x nand standard deviation std.
import numpy as np
from scipy import signal
def gaussian_kernel(n, std, normalised=False):
Generates a n x n matrix with a centered gaussian
of standard deviation std centered on it. If normalised,
its volume equals 1.'''
gaussian1D = signal.gaussian(n, std)
gaussian2D = np.outer(gaussian1D, gaussian1D)
if normalised:
gaussian2D /= (2*np.pi*(std**2))
return gaussian2D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.