Statistics Functions
statistics.geometric_mean()
Compute the geometric mean of positive data, useful for compounded growth factors. Negative or empty input raises StatisticsError. The rolling Python 3.13 documentation says zero is invalid, but CPython 3.13.5 returns 0.0 for finite nonnegative data containing zero. Use positive observations for portable examples; check the target runtime before depending on zero behavior.
Formal Syntax & Structure
python syntaxpython
statistics.geometric_mean(data)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | iterable of numbers | Observations used by the statistic. |
Return Value
float
Floating-point result; finite precision and domain restrictions apply.
Working Example
Example Snippetpython
import statisticsprint(round(statistics.geometric_mean([4, 9]), 6))