MCPcopy Index your code
hub / github.com/python/cpython / mean

Function mean

Lib/statistics.py:158–178  ·  view source on GitHub ↗

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("0.375")]

(data)

Source from the content-addressed store, hash-verified

156## Measures of central tendency (averages) #################################
157
158def mean(data):
159 """Return the sample arithmetic mean of data.
160
161 >>> mean([1, 2, 3, 4, 4])
162 2.8
163
164 >>> from fractions import Fraction as F
165 >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)])
166 Fraction(13, 21)
167
168 >>> from decimal import Decimal as D
169 >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")])
170 Decimal('0.5625')
171
172 If ``data`` is empty, StatisticsError will be raised.
173
174 """
175 T, total, n = _sum(data)
176 if n < 1:
177 raise StatisticsError('mean requires at least one data point')
178 return _convert(total / n, T)
179
180
181def fmean(data, weights=None):

Callers 1

_test_generatorFunction · 0.90

Calls 3

_sumFunction · 0.85
StatisticsErrorClass · 0.85
_convertFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…