how to calculate the Euclidean norm of a vector in R?

后端 未结 10 1194
灰色年华
灰色年华 2021-02-01 13:22

I tried norm, but I think it gives the wrong result. (the norm of c(1, 2, 3) is sqrt(1*1+2*2+3*3), but it returns 6..

10条回答
  •  自闭症患者
    2021-02-01 14:20

    Create your matrix as column vise using cbind then the norm function works well with Frobenius norm (the Euclidean norm) as an argument.

    x1<-cbind(1:3)

    norm(x1,"f")

    [1] 3.741657

    sqrt(1*1+2*2+3*3)

    [1] 3.741657

提交回复
热议问题