# Covariance with np.cov

Consider the matrix of 5 observations each of 3 variables, $x_0$, $x_1$ and $x_2$ whose observed values are held in the three rows of the array X:

X = np.array([ [0.1, 0.3, 0.4, 0.8, 0.9],
[3.2, 2.4, 2.4, 0.1, 5.5],
[10., 8.2, 4.3, 2.6, 0.9]
])


The covariance matrix is a $3 \times 3$ array of values,

In [x]: print( np.cov(X) )
[[  0.115 ,   0.0575,  -1.2325],
[  0.0575,   3.757 ,  -0.8775],
[ -1.2325,  -0.8775,  14.525 ]]


The diagonal elements, $C_{ii}$ are the variances in the variables $x_i$ assuming $N-1$ degrees of freedom:

In [x]: print(np.var(X, axis=1, ddof=1))
[  0.115   3.757  14.525]


Although the magnitude of the covariance matrix elements is not always easy to interpret (because it depends on the magnitude of the individual observations which may be very different for different variables), it is clear that there is a strong anti-correlation between $x_0$ and $x_2$ ($C_{02}=-1.2325$: as one increases the other decreases) and no strong correlation between $x_0$ and $x_1$ ($C_{01}=0.0575$: $x_0$ and $x_1$ do not trend strongly together).