[SciPy-User] Fitting a Gaussian

Benedikt Riedel briedel at wisc.edu
Mon Jan 17 17:29:37 EST 2011


Mygaussfit basically fits for the sigma, mu and A, for the function
f(x)=Aexp(-(x-mu)^2/(2sigma^2)). What I am most interested is the A in this
case and the sigma, since I am trying to compare two gaussians.

Thanks for the input.

Cheers,

Ben

On Mon, Jan 17, 2011 at 16:09, <josef.pktd at gmail.com> wrote:

> On Mon, Jan 17, 2011 at 4:55 PM, Benedikt Riedel <briedel at wisc.edu> wrote:
> > Hi all,
> >
> > I am a bit dumbfounded. I have been trying to figure out how to fit a
> > gaussian to a data set that I have. The only thing I have been able to
> dig
> > up with so far is that I have to get scipy to compute the mean and
> standard
> > deviation for me and then basically plug those into a gaussian. Just
> seems a
> > little bit odd to me considering that Octave has the mygaussfit function
> > included or is there an easier method?
>
> I don't know what a mygaussfit does, but we have this:
>
> >>> rvs = np.random.randn(200)
> >>> from scipy import stats
> >>> stats.norm.fit(rvs)
> (-0.0092383641087203858, 1.0567583206929831)
> >>> loc, scale = stats.norm.fit(rvs)
> >>> rvs.mean()
> -0.0092383641087203858
> >>> rvs.std()
> 1.0567583206929831
> >>> loc, scale
> (-0.0092383641087203858, 1.0567583206929831)
> >>> myfrozennorm = stats.norm(loc=loc, scale=scale)
> >>> myfrozennorm.cdf(2)
> 0.97137010763982468
> >>>
>
> This assumes that all observations are identically distributed and
> independent from each other. Otherwise, it get's a little bit more
> complicated.
>
> Josef
>
> >
> > Cheers,
> >
> > Ben
> >
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User at scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> >
> >
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



-- 
Benedikt Riedel
Graduate Student University of Wisconsin-Madison
Department of Physics
Office: 2304 Chamberlin Hall
Lab: 6247 Chamberlin Hall
Tel:  (608) 301-5736
Cell: (213) 519-1771
Lab: (608) 262-5916
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110117/6f7791fd/attachment.html>


More information about the SciPy-User mailing list