如何在Python中获得n个数组的n x n协方差矩阵?

时间:2022-01-26 04:39:00

For the following example code I am getting a 2x2 covariance matrix. How could I get a 3x3 covariance matrix instead?

对于以下示例代码,我得到一个2x2协方差矩阵。我怎么能得到一个3x3协方差矩阵呢?

a = [3,9,8,2]
b = [4,7,2,5]
c = [3,4,6,7]

cov_abc = np.cov(a,b,c)

print cov_abc

1 个解决方案

#1


Try

x = np.vstack([a,b,c])
cov = np.cov(x)

#1


Try

x = np.vstack([a,b,c])
cov = np.cov(x)