[New-bugs-announce] [issue26913] statistics.mean of bools

Peter Norvig report at bugs.python.org
Mon May 2 16:59:11 EDT 2016


New submission from Peter Norvig:

mean([True, True, True, False]) should be 0.75, but it returns 0.25.

The fix is to change _sum so that when the type is bool, the result should be coerced to int, not bool.

Why it is important for statistics.mean to work with bools:
It is natural to say something like
    mean(x > threshold for x in data)
and expect to get the percentage of items in data that are above threshold.

----------
components: Library (Lib)
messages: 264670
nosy: Peter.Norvig
priority: normal
severity: normal
status: open
title: statistics.mean of bools
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26913>
_______________________________________


More information about the New-bugs-announce mailing list