Return the sample arithmetic mean of data. >>> mean([1, 2, 3, 4, 4]) 2.8 >>> from fractions import Fraction as F >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)]) Fraction(13, 21) >>> from decimal import Decimal as D >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")]
(data)
| 156 | ## Measures of central tendency (averages) ################################# |
| 157 | |
| 158 | def mean(data): |
| 159 | """Return the sample arithmetic mean of data. |
| 160 | |
| 161 | >>> mean([1, 2, 3, 4, 4]) |
| 162 | 2.8 |
| 163 | |
| 164 | >>> from fractions import Fraction as F |
| 165 | >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)]) |
| 166 | Fraction(13, 21) |
| 167 | |
| 168 | >>> from decimal import Decimal as D |
| 169 | >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")]) |
| 170 | Decimal('0.5625') |
| 171 | |
| 172 | If ``data`` is empty, StatisticsError will be raised. |
| 173 | |
| 174 | """ |
| 175 | T, total, n = _sum(data) |
| 176 | if n < 1: |
| 177 | raise StatisticsError('mean requires at least one data point') |
| 178 | return _convert(total / n, T) |
| 179 | |
| 180 | |
| 181 | def fmean(data, weights=None): |
no test coverage detected
searching dependent graphs…