MLhacker
MLhacker

Reputation: 1512

Why are Scipy and Np Linalg producing different eigenvalues derived from the same matrix?

Why are Scipy and Np Linalg producing different eigenvalues derived from the same matrix?

import numpy as np
newMat = np.array([[3,2],[1,0]])

np.linalg.eigvals(newMat) 
#Eigenvalues: ([ 3.56155281, -0.56155281])


from scipy.linalg import eigh

eigvals, eigvecs = eigh(newMat)
#Eigenvalues: ([-0.30277564,  3.30277564])

Upvotes: 0

Views: 132

Answers (2)

JeeyCi
JeeyCi

Reputation: 589

import numpy as np
newMat = np.array([[3,2],[1,0]])

print(np.linalg.eigvals(newMat))
#Eigenvalues: ([ 3.56155281, -0.56155281])    

from scipy.linalg import eig
# eigvals, eigvecs = normalized left eigenvector if left=True. normalized right eigenvector if right=True.
print( np.real_if_close(eig(newMat)[0]))
#Eigenvalues: ([ 3.56155281 -0.56155281])

Upvotes: 0

donkopotamus
donkopotamus

Reputation: 23176

They produce different values because you are currently:

  • asking numpy to generate the eigenvalues of a matrix;
  • asking scipy to generate the eigenvalues of a matrix assuming the matrix is hermitian.

The matrix is not hermitian, thus the scipy results are incorrect. You can generate similarly incorrect eigenvalues from numpy by using its numpy.linalg.eigh function as well.

Upvotes: 3

Related Questions