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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:24:14  来源:igfitidea点击:

Standard deviation in numpy

pythonnumpystandard-deviation

提问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.stdreturns 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 ddofparameter to std():

默认情况下,numpy.std返回总体标准差,在这种情况下np.std([0,1])正确报告为0.5。如果您正在寻找样本标准偏差,您可以提供一个可选ddof参数std()

>>> np.std([0, 1], ddof=1)
0.70710678118654757

ddofmodifies the divisor of the sum of the squares of the samples-minus-mean. The divisor is N - ddof, where the default ddofis 0as you can see from your result.

ddof修改样本减去均值的平方和的除数。除数是N - ddof,默认值ddof0您从结果中看到的。