Standard deviation in numpy [duplicate]

筅森魡賤 提交于 2020-01-22 04:59:06

问题


Here is my code:

import numpy as np
print(np.std(np.array([0,1])))

it produces 0.5

I am confident that this is incorrect. What am I doing wrong?


回答1:


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():

>>> 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.



来源:https://stackoverflow.com/questions/34050491/standard-deviation-in-numpy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!