[issue27181] Add geometric mean to `statistics` module
Steven D'Aprano
report at bugs.python.org
Thu Jun 9 07:59:05 EDT 2016
Steven D'Aprano added the comment:
On Thu, Jun 09, 2016 at 09:24:04AM +0000, Mark Dickinson wrote:
> On the other hand, apparently `exp(mean(log(...)))` is good enough for SciPy:
Hmm, well, I don't have SciPy installed, but I've found that despite
their (well-deserved) reputation, numpy (and presumably scipy) often
have rather naive algorithms that can lose accuracy rather
spectacularly.
py> statistics.mean([1e50, 2e-50, -1e50, 2e-50])
1e-50
py> np.mean(np.array([1e50, 2e-50, -1e50, 2e-50]))
5e-51
py> statistics.mean([1e50, 2e-50, -1e50, 2e-50]*1000)
1e-50
py> np.mean(np.array([1e50, 2e-50, -1e50, 2e-50]*1000))
5.0000000000000002e-54
On the other hand, np is probably a hundred times (or more) faster, so I
suppose accuracy/speed makes a good trade off.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27181>
_______________________________________
More information about the Python-bugs-list
mailing list