25 lines
560 B
Python
25 lines
560 B
Python
# Importing various packages
|
|
import numpy as np
|
|
n = 100
|
|
# define two vectors
|
|
x = np.random.random(size=n)
|
|
y = 4+3*x+np.random.normal(size=n)
|
|
#scaling the x and y vectors
|
|
x = x - np.mean(x)
|
|
y = y - np.mean(y)
|
|
variance_x = np.sum(x@x)/n
|
|
variance_y = np.sum(y@y)/n
|
|
print(variance_x)
|
|
print(variance_y)
|
|
cov_xy = np.sum(x@y)/n
|
|
cov_xx = np.sum(x@x)/n
|
|
cov_yy = np.sum(y@y)/n
|
|
C = np.zeros((2,2))
|
|
C[0,0]= cov_xx/variance_x
|
|
C[1,1]= cov_yy/variance_y
|
|
C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
|
|
C[1,0]= C[0,1]
|
|
print(C)
|
|
Eigvals, Eigvecs = np.linalg.eig(C)
|
|
print(Eigvals)
|