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

NameTypeDescription
dataiterable of numbersObservations used by the statistic.
weightsiterable of numbers or NoneOptional 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]))
Python Reference