statistics

Standard library module View source

Descriptive statistics and distributions for native numeric data.

The API follows CPython 3.14, including weighted means, ranked correlation, regression, and kernel density estimation. Numeric aggregates return float; median_low, median_high, and modes preserve the input element type. Compensated floating-point arithmetic and widened integer intermediates avoid common cancellation and overflow errors, but do not provide Decimal/Fraction arithmetic. Random sampling accepts integer seeds. Remove NaNs before computing order statistics; native floats do not retain Python object identity for NaNs. Finite product overflow uses a fixed-point recovery accumulator. Supplied-center dispersion is scaled, and integer relational statistics use shifted origins; these can retain finite results and precision lost by CPython's float paths.

function median
median(data)
function median_low
median_low(data)
function median_high
median_high(data)
function median_grouped
median_grouped(data, interval = 1.0)
function mode
mode(data)
function multimode
multimode(data)
function quantiles
quantiles(data, n: int = 4, method: str = "exclusive")
function mean
mean(data)
function fmean
fmean(data, weights = None)
function geometric_mean
geometric_mean(data)
function harmonic_mean
harmonic_mean(data, weights = None)
function pvariance
pvariance(data, mu = None)
function pstdev
pstdev(data, mu = None)
function variance
variance(data, xbar = None)
function stdev
stdev(data, xbar = None)
function covariance
covariance(xdata, ydata)
function correlation
correlation(xdata, ydata, method: str = "linear")
function linear_regression
linear_regression(xdata, ydata, proportional: bool = False)
function kde
kde(data, h, kernel: str = "normal", cumulative: bool = False)

Return a kernel density or cumulative distribution estimator.

function kde_random
kde_random(data, h, kernel: str = "normal", seed: Optional[int] = None)

Return a sampler with a private random generator and optional integer seed.

class NormalDist
class NormalDist
Constructors 1
__init__
__init__(self, mu = 0.0, sigma = 1.0)
Properties 5
mean
@property
mean(self)
median
@property
median(self)
mode
@property
mode(self)
stdev
@property
stdev(self)
variance
@property
variance(self)
Methods 8
pdf
pdf(self, x)
cdf
cdf(self, x)
zscore
zscore(self, x)
inv_cdf
inv_cdf(self, p: float)
quantiles
quantiles(self, n: int = 4)
overlap
overlap(self, other: NormalDist)
samples
samples(self, n: int, seed: Optional[int] = None)
from_samples
from_samples(data)
Special methods 13
__add__
__add__(x1: NormalDist, x2: NormalDist)
__add__(x1: NormalDist, x2: float)
__sub__
__sub__(x1: NormalDist, x2: NormalDist)
__sub__(x1: NormalDist, x2: float)
__mul__
__mul__(x1: NormalDist, x2: float)
__truediv__
__truediv__(x1: NormalDist, x2: float)
__pos__
__pos__(x1: NormalDist)
__neg__
__neg__(x1: NormalDist)
__radd__
__radd__(x1: NormalDist, x2: float)
__rsub__
__rsub__(x1: NormalDist, x2: float)
__rmul__
__rmul__(x1: NormalDist, x2: float)
__eq__
__eq__(x1: NormalDist, x2: NormalDist)
__ne__
__ne__(self, other: NormalDist)
__hash__
__hash__(self)
__repr__
__repr__(self)