Python 统计模块 pvariance() 方法

实例

计算整个总体的方差:

  1. # Import statistics Library
  2. import statistics
  3. # Calculate the variance of an entire population
  4. print(statistics.pvariance([1, 3, 5, 7, 9, 11]))
  5. print(statistics.pvariance([2, 2.5, 1.25, 3.1, 1.75, 2.8]))
  6. print(statistics.pvariance([-11, 5.5, -3.4, 7.1]))
  7. print(statistics.pvariance([1, 30, 50, 100]))

定义与用法

statistics.pvariance() 方法计算整个总体的方差。

较大的方差表示数据分散,较小的方差表示数据紧密聚集在均值周围。

提示:要从数据样本计算方差,请查看 statistics.variance() 方法。


语法

  1. statistics.pvariance(data, xbar)

参数值

参数描述
data必填的。要使用的数据值(可以是任何序列、列表或迭代器)
xbar可选。给定数据的平均值(也可以是围绕非平均值点的第二个力矩)。如果省略(或设置为无),则自动计算平均值

注意:如果数据为空,则返回统计错误。


技术细节

返回值:一个 float 值,表示给定数据的总体方差
Python 版本:3.4

分类导航