I'm trying to reproduce the error function using scipy, not using the erf method.
This is my code:
#!/usr/bin/env python
import numpy as np
import math
from scipy.integrate import quad
def error_func(y):
return 2/math.sqrt(np.pi)*quad(np.exp(-y**2), 1, np.inf, args=(y))[0]
g = [error_func(x) for x in np.arange(-1,1,0.2)]
print g
This code returns the following error message:
File "./test.py", line 9, in <module>
g = [error_func(x) for x in np.arange(-1,1,0.2)]
File "./test.py", line 7, in error_func
return 2/math.sqrt(np.pi)*quad(np.exp(-y**2), 1, np.inf, args=(y))[0]
File "/usr/local/lib/python2.7/site-packages/scipy/integrate/quadpack.py", line 316, in quad
points)
File "/usr/local/lib/python2.7/site-packages/scipy/integrate/quadpack.py", line 383, in _quad
return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
quadpack.error: quad: first argument is not callable
If I understand correctly, the first argument of quad must be a function. I thing that I pass it right. What is going wrong in my code?
lambda y. Make sure you're running the code you think you are.scipy.integrate.quadexpects a function as its first argument. You give itnp.exp(-y**2), which is a number. Try replacing it withlambda x: np.exp(-x**2). Also, read thescipy.integrate.quaddocs: docs.scipy.org/doc/scipy-0.18.1/reference/generated/…