import numpy as np A = [45,37,42,35,39] B = [38,31,26,28,33] C = [10,15,17,21,12] data = np.array([A,B,C]) covMatrix = np.cov(data,bias=True) print (covMatrix)
Here is what the above code is Doing:
1. We create a list of lists, where each list contains the data for a single variable.
2. We convert the list of lists into a numpy array.
3. We use the numpy cov function to calculate the covariance matrix.
4. We print the covariance matrix.
The output of the above code is:
[[11. 8.4 9.6]
[ 8.4 6.6 5.4]
[ 9.6 5.4 4.8]]
The diagonal elements of the covariance matrix are the variances of the three variables.
The off-diagonal elements are the covariances between the variables.