Python numpy 中的标准差
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34050491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Standard deviation in numpy
提问by user1700890
Here is my code:
这是我的代码:
import numpy as np
print(np.std(np.array([0,1])))
it produces 0.5
它产生 0.5
I am confident that this is incorrect. What am I doing wrong?
我相信这是不正确的。我究竟做错了什么?
采纳答案by Mad Physicist
By default, numpy.std
returns the population standard deviation, in which case np.std([0,1])
is correctly reported to be 0.5
. If you are looking for the sample standard deviation, you can supply an optional ddof
parameter to std()
:
默认情况下,numpy.std
返回总体标准差,在这种情况下np.std([0,1])
正确报告为0.5
。如果您正在寻找样本标准偏差,您可以提供一个可选ddof
参数std()
:
>>> np.std([0, 1], ddof=1)
0.70710678118654757
ddof
modifies the divisor of the sum of the squares of the samples-minus-mean. The divisor is N - ddof
, where the default ddof
is 0
as you can see from your result.
ddof
修改样本减去均值的平方和的除数。除数是N - ddof
,默认值ddof
是0
您从结果中看到的。