Gaussian Fit in PythonCreated on 2014-11-30 (Sun)Gaussian fitting in Python... what a pain. Have you ever wanted to fit some data to a Gaussian in Python in 2 minutes? I did. It's easy right... there must be a function that does least square fits... hopefully there's some instructions on how to use it. Call it with a Gaussian as the work function and you are done. Or so I thought. I also thought it would be smart to get on stackoverflow.com and see what code lurked around there. So this is the story of what I found:I started with this incorrect - just plain wrong version (note to self 1: post a message correcting it). Then I got to this version which is confusing if you want to get a Gaussian in 2 minutes. Though this last version had an interesting side link - which even though not about Gaussians is somewhat relevant to fitting functions. Finally I get to this correct starting point - which was a non-fitted version of what I wanted (note to self 2: in the future use the Cookbook more than stackoverflow). Then once I got confident I was on the right path there's this bug related to using floats - a strange apparition waiting to ruin my day. So without much further ado here is - finally - my correct and functional version:
|