Skip to content

Instantly share code, notes, and snippets.

@GeorgeSeif
Created November 9, 2018 02:17
Show Gist options
  • Select an option

  • Save GeorgeSeif/d1770bc4cf5438cfa0800c2ae8ff9b2a to your computer and use it in GitHub Desktop.

Select an option

Save GeorgeSeif/d1770bc4cf5438cfa0800c2ae8ff9b2a to your computer and use it in GitHub Desktop.
# Compute the eigen values and vectors using numpy
eig_vals, eig_vecs = np.linalg.eig(cov_mat)
# Make a list of (eigenvalue, eigenvector) tuples
eig_pairs = [(np.abs(eig_vals[i]), eig_vecs[:,i]) for i in range(len(eig_vals))]
# Sort the (eigenvalue, eigenvector) tuples from high to low
eig_pairs.sort(key=lambda x: x[0], reverse=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment