Convert data to floats and compute the geometric mean. Raises a StatisticsError if the input dataset is empty, if it contains a zero, or if it contains a negative value. No special efforts are made to achieve exact results. (However, this may change in the future.) >>>
(data)
| 472 | |
| 473 | |
| 474 | def geometric_mean(data): |
| 475 | """Convert data to floats and compute the geometric mean. |
| 476 | |
| 477 | Raises a StatisticsError if the input dataset is empty, |
| 478 | if it contains a zero, or if it contains a negative value. |
| 479 | |
| 480 | No special efforts are made to achieve exact results. |
| 481 | (However, this may change in the future.) |
| 482 | |
| 483 | >>> round(geometric_mean([54, 24, 36]), 9) |
| 484 | 36.0 |
| 485 | """ |
| 486 | try: |
| 487 | return exp(fmean(map(log, data))) |
| 488 | except ValueError: |
| 489 | raise StatisticsError('geometric mean requires a non-empty dataset ' |
| 490 | 'containing positive numbers') from None |
| 491 | |
| 492 | |
| 493 | def harmonic_mean(data, weights=None): |
nothing calls this directly
no test coverage detected