numpy covariance matrix

前端 未结 10 1615
半阙折子戏
半阙折子戏 2021-01-01 13:10

Suppose I have two vectors of length 25, and I want to compute their covariance matrix. I try doing this with numpy.cov, but always end up with a 2x2 matrix.



        
10条回答
  •  生来不讨喜
    2021-01-01 13:47

    As pointed out above, you only have two vectors so you'll only get a 2x2 cov matrix.

    IIRC the 2 main diagonal terms will be sum( (x-mean(x))**2) / (n-1) and similarly for y.

    The 2 off-diagonal terms will be sum( (x-mean(x))(y-mean(y)) ) / (n-1). n=25 in this case.

提交回复
热议问题