Skip to main content

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.

class StatisticsError
class StatisticsError(ValueError)
Constructors 1
__init__
__init__(self: Self, message: str = "", /)
function median
median(data) -> float
function median_low
median_low(data)
function median_high
median_high(data)
function median_grouped
median_grouped(data, interval = 1.0) -> float
function mode
mode(data)
function multimode
multimode(data)
function quantiles
quantiles(data, *, n: int = 4, method: str = "exclusive") -> List[float]
function mean
mean(data) -> float
function fmean
fmean(data, weights = None) -> float
function geometric_mean
geometric_mean(data) -> float
function harmonic_mean
harmonic_mean(data, weights = None) -> float
function pvariance
pvariance(data, mu = None) -> float
function pstdev
pstdev(data, mu = None) -> float
function variance
variance(data, xbar = None) -> float
function stdev
stdev(data, xbar = None) -> float
function covariance
covariance(xdata, ydata, /) -> float
function correlation
correlation(xdata, ydata, /, *, method: str = "linear") -> float
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: Self, mu = 0.0, sigma = 1.0)
Properties 5
mean
@property
mean(self: Self)
median
@property
median(self: Self)
mode
@property
mode(self: Self)
stdev
@property
stdev(self: Self)
variance
@property
variance(self: Self)
Methods 8
pdf
pdf(self: Self, x)
cdf
cdf(self: Self, x)
zscore
zscore(self: Self, x)
inv_cdf
inv_cdf(self: Self, p: float)
quantiles
quantiles(self: Self, n: int = 4)
overlap
overlap(self: Self, other: NormalDist) -> float
samples
samples(self: 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: Self, other: NormalDist, /)
__hash__
__hash__(self: Self)
__repr__
__repr__(self: Self)