Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get n x n covariance matrix for n arrays in Python?

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

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
like image 451
PyLabour Avatar asked May 05 '15 11:05

PyLabour


1 Answers

Try

x = np.vstack([a,b,c])
cov = np.cov(x)
like image 179
Donbeo Avatar answered Oct 18 '22 03:10

Donbeo