math.erf(x) returns the Gauss error function of x as a float between -1.0 and 1.0.
Added in Python 3.2, it lets you compute Gaussian (normal) probabilities directly without external libraries: the probability within z standard deviations of the mean is math.erf(z / math.sqrt(2)). For extreme tails near 1.0, prefer math.erfc().
math.erf() is a function in Python's standard math module: import it with import math and call math.erf(...), or import the name directly with from math import erf.
Syntax
Import math and pass a real number.
python
import math
prob = math.erf(x)
Call
What it does
math.erf(0)
Returns 0.0.
math.erf(1)
Returns approximately 0.842701....
math.erf(float("inf"))
Returns 1.0.
math.erf(float("-inf"))
Returns -1.0.
Notice math.erf() is an odd function: math.erf(-x) == -math.erf(x). Use math.erfc() for 1 - erf(x) when x > 4.
Function signatures
python
math.erf(x, /)
# added in Python 3.2; returns float error function in [-1.0, 1.0]
Parameters
Parameter
Description
x
Required positional real number (int or float).
Return Value
Return Value
Description
float
Value in [-1.0, 1.0]; 1.0 for inf, -1.0 for -inf, nan for nan.
Python Examples
Example 1 — Verify the 68-95-99.7 Normal Distribution Rule
Calculate the share of normal observations falling within one, two, and three standard deviations.
python
import math
for sigma in [1, 2, 3]:
share = math.erf(sigma / math.sqrt(2.0))
print(f"+/-{sigma} sigma -> {share:.4f}")