Statistics Functions
statistics.fmean()
Calculate a floating-point arithmetic mean, optionally weighting each observation. Weights must match the number of data items and have nonzero total. Mismatched weight lengths raise ValueError (StatisticsError on the tested build, a subclass of ValueError).
Formal Syntax & Structure
python syntaxpython
statistics.fmean(data, weights=None)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | iterable of numbers | Observations used by the statistic. |
| weights | iterable of numbers or None | Optional weights, one per observation. |
Return Value
float
Floating-point result; finite precision and domain restrictions apply.
Working Example
Example Snippetpython
import statisticsprint(statistics.fmean([10, 20], weights=[1, 3]))