statistics
Descriptive statistics over numeric sequences — mean, median, variance, and standard deviation (population and sample).
import statistics
statistics.mean([2, 4, 4, 4, 5, 5, 7, 9]) # 5.0
statistics.median([3, 1, 2]) # 2.0
statistics.stdev([1, 2, 3, 4, 5]) # sample std-devThis is a header-only module: every function is a template constrained by the NumericRange concept, so it accepts any iterable of arithmetic values (list[float], array[int], …).
Functions
Reductions:
sum(data)— sum of the elements (asdouble).count(data)— number of elements.mean(data)— arithmetic mean (0.0 if empty).
Spread:
pvariance(data)/pstdev(data)— population variance / std-dev (÷ N).variance(data)/stdev(data)— sample variance / std-dev (÷ N−1).
Order statistics:
median(data)— middle value, or the mean of the two middle values.
Per-function docs (parameters, runtime complexity, heap behavior) are in statistics.hpp. Tested in ../tests/statistics_test.cpp; ASan + Valgrind clean via the QA gate (security/run-valgrind.sh).
Functions
Sum of the elements.
Accumulates every element into a double, so an empty range sums to 0.0 and integer inputs are widened before adding (no integer overflow).
data | the numeric range. |
Σdata as double.
O(n) single pass.
none.
CheatahStatistics.SumCountMeanStatisticsCompileRun.SumStdlibE2E.StatisticsElement count.
data | the numeric range. |
the number of elements.
O(n) single pass.
none.
CheatahStatistics.SumCountMeanStatisticsCompileRun.CountStdlibE2E.StatisticsArithmetic mean.
Computes sum/count, but guards division by zero: an empty range returns 0.0 rather than NaN.
data | the numeric range. |
the mean, or 0.0 if empty.
O(n) (two passes: count + sum).
none.
CheatahStatistics.SumCountMeanStatisticsCompileRun.MeanPopulation variance (divide by N).
Mean of the squared deviations from the mean, dividing by N (treats data as the entire population). Returns 0.0 for an empty or single-element range.
data | the numeric range. |
the variance, or 0.0 if empty.
O(n).
none.
StatisticsCompileRun.PvarianceStdlibE2E.StatisticsPopulation standard deviation.
Square root of pvariance, so it is 0.0 for empty or single-element ranges and never negative.
data | the numeric range. |
√pvariance(data).
O(n).
none.
StatisticsCompileRun.PstdevStdlibE2E.StatisticsSample variance (divide by N−1).
Sum of squared deviations from the mean divided by N−1 (Bessel's correction, estimating the variance of the wider population from a sample). Requires at least two elements; an empty or single-element range returns 0.0 rather than dividing by zero.
data | the numeric range. |
the variance, or 0.0 if fewer than 2 elements.
O(n).
none.
StatisticsCompileRun.VarianceStdlibE2E.StatisticsSample standard deviation.
Square root of variance, so it is 0.0 when there are fewer than two elements.
data | the numeric range. |
√variance(data).
O(n).
none.
StatisticsCompileRun.StdevMedian (mean of the two middle values when the count is even).
Copies the elements into a double vector, sorts ascending, and returns the middle value (averaging the two central values when the count is even). Returns 0.0 for an empty range.
data | the numeric range. |
the median, or 0.0 if empty.
O(n log n) — copies the elements into a vector and sorts.
allocates a temporary std::vector<double>.
CheatahStatistics.MedianOddAndEvenStatisticsCompileRun.MedianStdlibE2E.Statistics SystemApps.GradeReport