gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 22:12:55 26 4
gpt4 key购买 nike

我有一个列表:

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 计算总体 标准默认偏差(它的行为类似于 Excel 的 STDEVP)。

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

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

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

关于python - numpy.std 和 excel STDEV 函数之间有什么区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34133939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com