In [2]:
import numpy as np
In [23]:
cov = np.array([[5, -3, 0],[-3, 5, 0],[0, 0, 4]])
cov
Out[23]:
In [24]:
evals, evecs = np.linalg.eig(cov)
In [25]:
evals
Out[25]:
In [26]:
evecs
Out[26]:
In [84]:
x=np.array([[4,0,2]])
x
Out[84]:
In [85]:
components = np.array([evecs[:,0], evecs[:,2]]).T #these are the 2 vecs w/ most variance
U = components
U
Out[85]:
In [86]:
x2d = np.dot(U.T,x.T).T
x2d
Out[86]:
In [87]:
UUT = np.dot(U,U.T)
UUT
Out[87]:
In [89]:
x3d = np.dot(UUT, x.T)
x3d.T
Out[89]: