Skip to content

Instantly share code, notes, and snippets.

@j-faria
Created January 31, 2019 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-faria/576e18f0c4f5f2dc43bf2767b164286e to your computer and use it in GitHub Desktop.
Save j-faria/576e18f0c4f5f2dc43bf2767b164286e to your computer and use it in GitHub Desktop.
Fit all the sines
from numpy import sin
from scipy import optimize
sine = lambda t, p: p[0] * sin(1. / p[1] * t + p[2]) + p[3]
sinefit = lambda t, y, ye, p0, **kwargs: optimize.leastsq(lambda p, t, y, ye: (sine(t, p) - y)/ye, p0, args=(t, y, ye), **kwargs)[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment