Starting Python 3.8
, the standard library provides the NormalDist
object as part of the statistics
module.
It can be used to get the probability density function (pdf
- likelihood that a random sample X will be near the given value x) for a given mean (mu
) and standard deviation (sigma
):
from statistics import NormalDist
NormalDist(mu=100, sigma=12).pdf(98)
# 0.032786643008494994
Also note that the NormalDist
object also provides the cumulative distribution function (cdf
- probability that a random sample X will be less than or equal to x):
NormalDist(mu=100, sigma=12).cdf(98)
# 0.43381616738909634