Skip to content

Instantly share code, notes, and snippets.

@akira093
Created November 8, 2013 04:08
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 akira093/7366144 to your computer and use it in GitHub Desktop.
Save akira093/7366144 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from scipy import optimize
import pylab
import numpy
num = 100000
bin = 1000
e1 = numpy.random.normal(0, 1, num)
e2 = numpy.random.normal(0, 1, num)
y, x = numpy.histogram(e1-e2, bin)
def fitFunc(p, x):
return p[0] * pylab.exp(-(x-p[1])**2 / 2 / p[2])
result = optimize.leastsq(fitFunc, [1, 0, 1], args = x)
print(result)
print(y, x)
pylab.subplot(121)
pylab.hist(e1-e2, bin)
pylab.subplot(122)
pylab.plot(x, fitFunc(result[0], x), "r")
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment