typestar

The statistics module in Python

Mean, median, spread and quantiles without reaching for numpy.

import statistics

runs = [88, 91, 97, 104, 99, 108, 92]

print(statistics.fmean(runs), statistics.median(runs))
print(round(statistics.stdev(runs), 2), round(statistics.pstdev(runs), 2))
print(statistics.quantiles(runs, n=4))
print(statistics.mode([1, 2, 2, 3]), statistics.multimode([1, 1, 2, 2]))
print(round(statistics.correlation(runs, sorted(runs)), 3))

How it works

  1. fmean is the fast float mean; mean is exact for Fractions.
  2. quantiles cuts the data into n groups.
  3. stdev is the sample deviation, pstdev the population one.

Keywords and builtins used here

The run, in numbers

Lines
9
Characters to type
359
Tokens
125
Three-star pace
105 tpm

At the three-star pace of 105 tokens a minute, this run takes about 71 seconds.

Type this snippet

Step 3 of 3 in Configuration & time, step 34 of 41 in Domain tools.

← Previous Next →