Numpy Gauss Error Function
Contents |
2/sqrt(pi)*integral(exp(-t**2), t=0..z). Parameters:x module 'scipy' has no attribute 'special' : ndarray Input array. Returns:res : ndarray The values of scipy erfinv the error function at the given points x. See also erfc, erfinv, erfcinv Notes The cumulative of the unit normal distribution
Python Erfc
is given by Phi(z) = 1/2[1 + erf(z/sqrt(2))]. References [R200]http://en.wikipedia.org/wiki/Error_function [R201]Milton Abramowitz and Irene A. Stegun, eds. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. New York: Dover, 1972. http://www.math.sfu.ca/~cbm/aands/page_297.htm [R202]Steven G. Johnson, Faddeeva W function implementation. http://ab-initio.mit.edu/Faddeeva Previous topic scipy.special.multigammaln Next topic scipy.special.erfc © Copyright 2008-2009, The Scipy community. Last updated on May 11, 2014. Created using Sphinx 1.2.2.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this python cumulative distribution function site About Us Learn more about Stack Overflow the company Business Learn more scipy special about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Python Error Handling Best Practices
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Is there https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.special.erf.html an easily available implementation of erf() for Python? up vote 36 down vote favorite 7 I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and it's not even clear http://stackoverflow.com/questions/457408/is-there-an-easily-available-implementation-of-erf-for-python which one!). I'm sorry if this is a naive question - I'm totally new to Python. python math share|improve this question asked Jan 19 '09 at 12:10 rog 2,21211721 add a comment| 7 Answers 7 active oldest votes up vote 44 down vote Since v.2.7. the standard math module contains erf function. This should be the easiest way. http://docs.python.org/2/library/math.html#math.erf share|improve this answer edited Nov 19 '13 at 14:28 Colonel Panic 53.2k33221278 answered Jul 12 '11 at 9:31 bezalel 59146 1 +1: simplest answer. –Neil G Dec 21 '11 at 4:42 Wow! Never noticed that! –smci May 20 '13 at 23:30 Is there a Python module that provides erf⻹(x) ? –Lori Feb 1 '15 at 22:49 add a comment| up vote 39 down vote I recommend SciPy for numerical functions in Python, but if you want something with no dependencies, here is a function with an error error is less than 1.5 * 10-7 for all inputs. def erf(x): # save the sign of x sign = 1 if x >= 0 else -1 x = abs(x) # constants a1 = 0.254829592 a2 = -0.284496736 a3 =
Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. http://rajeshrinet.github.io/blog/2014/numpy-matplotlib/ In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. error function Namespaces are one honking great idea -- let's do more of those! Plotting using matplotlib In[2]: %matplotlib inline import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 4*np.pi, 64) plt.plot(x, np.sin(x), '*-'); We can improve on the above plot in several ways. E.g setting axis labels. setting axis limits. chossing color of our choice. putting legends ... In the plot below we have included some of these features along numpy gauss error with another plot in the same figure. This can be used to compare between two plots on the same figure. In[13]: %matplotlib inline import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 4*np.pi, 64) plt.plot(x, np.sin(x), color="#348ABD", linewidth=2, linestyle="-", label='sin(x)'); plt.plot(x, np.cos(x), color="#A60628", linewidth= 3, linestyle="-", label='cos(x)'); plt.xlim([0, 4*np.pi]); plt.xlabel('x'); plt.legend(loc="lower left") Out[13]: