Finding the sigma of a Gaussian array without using a fit

1.1k views Asked by At

I have an array, called gaussian_array, which is made of a series of numbers that, once plotted, form a Gaussian, to a good approximation. I need to understand the \sigma of this Gaussian, but I am not allowed to use a fit of any kind. What I have tried so far is to calculate the peak of the Gaussian, which is given by the first element of the array (the Gaussian is centred around the origin), gaussian_array[0], and then somehow I thought it could be useful to use the FWHM and the well known relation between \sigma and the FWHM. However, I do not know exactly how to implement this in python. I thought it could have been useful to write something like

for i in range(len(gaussian_array)):
    if gaussian[i] = FWHM:
        sigma = gaussian[i]/(2.*np.sqrt(2.np.log(2)))

but I don't think that's a reliable procedure, because it will not always be true that a certain element of the gaussian_array will EXACTLY coincide to the calculated FWHM. I cannot even calculate the standard deviation by the sum of the squares of the differences between the values and the origin. So, how could I estimate the sigma of this gaussian_array?

1

There are 1 answers

0
Alexander McFarlane On

I am confused why you would go to such great lengths to calculate a standard deviation. In you post it seems you are trying to get the \sigma by this relation

enter image description here

If you are trying to obtain the standard deviation, just use numpy

import numpy as np

# method 1 - use np.std() on a python data structure
sigma = np.std(gaussian_array)    

# method 2 - convert to numpy array and use .std() method
gaussian_array = np.asarray(gaussian_array)
sigma = gaussian_array.std()