Python 3.8+statisticsterm
statistics.NormalDist
distribution
A normal distribution (μ, σ) with pdf/cdf/samples and arithmetic.
Syntax
statistics.NormalDist(mu=0.0, sigma=1.0)
Instances are immutable, and arithmetic such as nd * 2 or nd + 5 returns a new distribution; adding two NormalDist objects assumes the variables are independent, so the result is wrong for correlated ones. cdf(x) gives the share of values at or below x, the reverse question — the cutoff for a given probability — is inv_cdf, and from_samples builds a distribution straight from data. Added in Python 3.8.
Examples
import statistics
nd = statistics.NormalDist(0, 1)
print(nd.mean, nd.stdev) # → 0.0 1.0
print(round(nd.cdf(0), 2)) # → 0.5
See also
Open in the full glossarydocs.python.orgReport an inaccuracy