<分区> 分区>
当我尝试使用 numpy 和 R 计算标准偏差时,我得到了两个不同的结果。 我可能缺少一些愚蠢的东西,但是什么?
R代码
x1=matrix(c(1,7,5,8,9,5,4,5,4,3,76,8),nrow=4)
std=sd(x1[,1])
mean=mean(x1[,1])
std=apply(X=x1,MARGIN=2,FUN=sd)
std
> x1=matrix(c(1,7,5,8,9,5,4,5,4,3,76,8),nrow=4)
> std=sd(x1[,1])
> std=apply(X=x1,MARGIN=2,FUN=sd)
> std
[1] 3.095696 2.217356 35.565667
Python代码
import numpy as np
x1=np.matrix([[1.,9.,4.],[7.,5.,3.],[5.,4.,76.],[8.,5.,8.]])
std=np.apply_along_axis(func1d=np.std,axis=0,arr=x1)
std
Out[9]: array([ 2.68095132, 1.92028644, 30.80077109])
