numpy covariance matrix

前端 未结 10 1702
半阙折子戏
半阙折子戏 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

    Try this:

    import numpy as np
    x=np.random.normal(size=25)
    y=np.random.normal(size=25)
    z = np.vstack((x, y))
    c = np.cov(z.T)
    

提交回复
热议问题