numpy.std 和 excel STDEV 函数之间有什么区别吗?

Is there any difference between numpy.std and excel STDEV function?

我有一个列表:

s = [0.995537725, 0.994532199, 0.996027983, 0.999891383, 1.004754272, 1.003870012, 0.999888944, 0.994438078, 0.992548715, 0.998344545, 1.004504764, 1.00883411]

我在Excel计算它的标准差,得到的答案是:0.005106477,我用的函数是:=STDEV(C5:N5)

然后我使用 numpy.std 进行相同的计算:

import numpy as np

print np.std(s)

然而,我得到了答案:0.0048890791894

我什至编写了自己的标准函数:

def std(input_list):
        count = len(input_list)

        mean = float(sum(input_list)) / float(count)

        overall = 0.0
        for i in input_list:
            overall = overall + (i - mean) * (i - mean)

        return math.sqrt(overall / count)

我自己的函数给出了与 numpy 相同的结果。

所以我想知道有这样的区别吗?还是我弄错了?

有区别:Excel的STDEV计算样本标准差,而NumPy的std计算 ]population 默认标准偏差(它表现得像 Excel 的 STDEVP)。

要使 NumPy 的 std 函数表现得像 Excel 的 STDEV,请传入值 ddof=1:

>>> np.std(s, ddof=1)
0.0051064766704396617

这会使用样本方差计算 s 的标准差(即除以 n-1 而不是 n。)