Skip to content

Instantly share code, notes, and snippets.

Last active November 17, 2019 08:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
eigenvectors from eigenvalues
# To calculate eigenvectors of a Hermitian matrix using nothing but the eigenvalues
# from
import numpy as np
# use numpy to calculate the eigen values
e_vals = np.linalg.eigvals(mat)
eigen_vectors = np.zeros_like(mat)
n, _ = mat.shape
for i in range(n):
for j in range(n):
lhs_product = 1
for k in range(n):
if k != i:
lhs_product *= (e_vals[i] - e_vals[k])
# remove the jth row and column from the matrix
Mj = np.delete(np.delete(mat, j, axis=0), j, axis=1)
e_vals_j = np.linalg.eigvals(Mj)
rhs_product = 1
for k in range(n-1):
rhs_product *= (e_vals[i] - e_vals_j[k])
eigen_vectors[i,j] = np.sqrt(rhs_product / lhs_product)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment