Skip to content

Instantly share code, notes, and snippets.

@escuccim
Last active November 17, 2019 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save escuccim/09f363f71d41c23fae9db0e52506a72a to your computer and use it in GitHub Desktop.
Save escuccim/09f363f71d41c23fae9db0e52506a72a to your computer and use it in GitHub Desktop.
eigenvectors from eigenvalues
# To calculate eigenvectors of a Hermitian matrix using nothing but the eigenvalues
# from https://arxiv.org/pdf/1908.03795.pdf
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