Skip to content

Instantly share code, notes, and snippets.

# andrewgiessel/gist:4635563 Last active Apr 5, 2019

simple numpy based 2d gaussian function
 import numpy as np def makeGaussian(size, fwhm = 3, center=None): """ Make a square gaussian kernel. size is the length of a side of the square fwhm is full-width-half-maximum, which can be thought of as an effective radius. """ x = np.arange(0, size, 1, float) y = x[:,np.newaxis] if center is None: x0 = y0 = size // 2 else: x0 = center y0 = center return np.exp(-4*np.log(2) * ((x-x0)**2 + (y-y0)**2) / fwhm**2)

### samueltwum1 commented Jul 7, 2016 • edited

 Does this formula reflect the 2D gaussian here How can this code be modified to make the gaussian asymmetric?

 TE AMO

### lalit184 commented Aug 22, 2018

 this is not a standard gaussian function as you do not take into account when off diagonal elms are non zero

### cfgnunes commented Apr 5, 2019

 I think that the return must be: `return np.exp(-((x-x0)**2 + (y-y0)**2) / fwhm**2)` without the part: "4*np.log(2)" According the equation. See: https://en.wikipedia.org/wiki/Gaussian_function
to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.