Python Glossary Русский

Python 3.2+Numbers & mathfunction

math.erf

special functions

The error function (Gauss integral); used in statistics.

Syntax

math.erf(...)

The function is odd and saturates quickly: from about x = 6 the result rounds to exactly 1.0, so 1 - erf(x) collapses to zero for large arguments and erfc is what you want there. If the task is really about the normal distribution, statistics.NormalDist().cdf() is a shorter road than assembling the formula out of erf by hand.

Examples

import math
print(math.erf(0))   # → 0.0
print(round(math.erf(1), 4))   # → 0.8427
print(round(math.erf(-1), 4))   # → -0.8427
print(round(math.erf(1 / math.sqrt(2)), 4))   # → 0.6827
print(math.erf(float('inf')))   # → 1.0

See also

Open in the full glossarydocs.python.orgReport an inaccuracy