In [5]:
# import numpy for doing the math/making matrices
import numpy as np
In [9]:
# [[1, 2, 1.5], [3, 4, 5], [10, 5, 2]]
arr = [[2, 3, 4, 6], [2, 2.5, 4, 4.5]]
arr2 = [[1, 2, 1.5], [3, 4, 5], [10, 5, 2]]
In [10]:
# calculate the variance/covariance
# np.var(arr, ddof = 1)
# np.cov(arr)
# ddof = 1 means use bessel's correction
print(np.var(arr[0], ddof = 1))
print(np.cov(arr))
print(np.cov(arr2))
2.9166666666666665
[[2.91666667 1.91666667]
 [1.91666667 1.41666667]]
[[ 0.25        0.25       -1.25      ]
 [ 0.25        1.         -4.        ]
 [-1.25       -4.         16.33333333]]
In [11]:
# calculate the coref values
# np.corrcoef(arr)
print(np.corrcoef(arr2))
[[ 1.          0.5        -0.61858957]
 [ 0.5         1.         -0.98974332]
 [-0.61858957 -0.98974332  1.        ]]
In [ ]: