Skip to content

Instantly share code, notes, and snippets.

@escuccim escuccim/vecs_from_vals.py
Last active Nov 17, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.