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
(data)
| 412 | # === Measures of central tendency (averages) === |
| 413 | |
| 414 | def mean(data): |
| 415 | """Return the sample arithmetic mean of data. |
| 416 | |
| 417 | >>> mean([1, 2, 3, 4, 4]) |
| 418 | 2.8 |
| 419 | |
| 420 | >>> from fractions import Fraction as F |
| 421 | >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)]) |
| 422 | Fraction(13, 21) |
| 423 | |
| 424 | >>> from decimal import Decimal as D |
| 425 | >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")]) |
| 426 | Decimal('0.5625') |
| 427 | |
| 428 | If ``data`` is empty, StatisticsError will be raised. |
| 429 | """ |
| 430 | T, total, n = _sum(data) |
| 431 | if n < 1: |
| 432 | raise StatisticsError('mean requires at least one data point') |
| 433 | return _convert(total / n, T) |
| 434 | |
| 435 | |
| 436 | def fmean(data, weights=None): |
no test coverage detected