3 ms·
It looks like the second. For many of its operations, the statistics module first converts floats to integer ratios (integers are bignums in Python), does inter
by _delirium 5y ago
It looks like the second. For many of its operations, the statistics module first converts floats to integer ratios (integers are bignums in Python), does intermediate operations using integer arithmetic, and converts back to floats at the end.
Here's the internal _sum function for example, which you can see maps _exact_ratio over the data before summing: https://github.com/python/cpython/blob/3.9/Lib/statistics.py#L123 https://github.com/python/cpython/blob/3.9/Lib/statistics.py...
- eesmith 5y agoThere's also fmean() which is for floats: >>> data = (1_000_000_000.1, 1.1) * 50_000 >>> statistics.fmean(data) 500000000.6 Implementation at https://github.com/python/cpython/blob/6df926f1c46eb6db7b5dcd0227c6b532c78525c9/Modules/mathmodule.c#L1314 https://github.com/python/cpython/blob/6df926f1c46eb6db7b5dc... .
- eesmith 5y agoI just found that boltons supports a mean, in boltons.statsutils.mean . It appears to use the naive summation: >>> import boltons.statsutils >>> data = (1_000_000_000.1, 1.1) * 50_000 >>> boltons.statsutils.mean(data) 500000000.60091573 >>> sum(data) / len(data) 500000000.60091573