MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / pvariance

Function pvariance

tools/python-3.11.9-amd64/Lib/statistics.py:866–904  ·  view source on GitHub ↗

Return the population variance of ``data``. data should be a sequence or iterable of Real-valued numbers, with at least one value. The optional argument mu, if given, should be the mean of the data. If it is missing or None, the mean is automatically calculated. Use this func

(data, mu=None)

Source from the content-addressed store, hash-verified

864
865
866def pvariance(data, mu=None):
867 """Return the population variance of ``data``.
868
869 data should be a sequence or iterable of Real-valued numbers, with at least one
870 value. The optional argument mu, if given, should be the mean of
871 the data. If it is missing or None, the mean is automatically calculated.
872
873 Use this function to calculate the variance from the entire population.
874 To estimate the variance from a sample, the ``variance`` function is
875 usually a better choice.
876
877 Examples:
878
879 >>> data = [0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25]
880 >>> pvariance(data)
881 1.25
882
883 If you have already calculated the mean of the data, you can pass it as
884 the optional second argument to avoid recalculating it:
885
886 >>> mu = mean(data)
887 >>> pvariance(data, mu)
888 1.25
889
890 Decimals and Fractions are supported:
891
892 >>> from decimal import Decimal as D
893 >>> pvariance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")])
894 Decimal('24.815')
895
896 >>> from fractions import Fraction as F
897 >>> pvariance([F(1, 4), F(5, 4), F(1, 2)])
898 Fraction(13, 72)
899
900 """
901 T, ss, c, n = _ss(data, mu)
902 if n < 1:
903 raise StatisticsError('pvariance requires at least one data point')
904 return _convert(ss / n, T)
905
906
907def stdev(data, xbar=None):

Callers

nothing calls this directly

Calls 3

_ssFunction · 0.85
StatisticsErrorClass · 0.85
_convertFunction · 0.70

Tested by

no test coverage detected