Created
May 3, 2018 14:50
-
-
Save biggzlar/dfedf54bb622115c41cf4ca5db2236b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from matplotlib import pyplot as plt | |
mean = [0, 0] | |
cov = [[1., .5], [.5, 1.]] | |
m = 128 | |
X = np.random.multivariate_normal(mean, cov, m) | |
cov = np.cov(X.T) | |
eig_val, eig_vec = np.linalg.eigh(cov) | |
eig_vec[0,:] = eig_vec[0,:] * eig_val[0] | |
eig_vec[1,:] = eig_vec[1,:] * eig_val[1] | |
plt.figure(figsize=(8, 8)) | |
plt.plot(X[:,0], X[:,1], 'o') | |
plt.arrow(mean[0], mean[1], eig_vec[0, 0], eig_vec[0, 1]) | |
plt.arrow(mean[0], mean[1], eig_vec[1, 0], eig_vec[1, 1]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment