Numpy giving wrong Eigenvectors


from numpy.linalg import eig
import numpy as np

A = np.array([[1,2],[3,4]])
eval, evec = eig(A)

print("Eigenvectors:", evec)


Eigenvectors: [[-0.82456484 -0.41597356]
               [ 0.56576746 -0.90937671]]

while in mathematica:

A = {{1, 2}, {3, 4}};
{eval, evec} = Eigensystem[A];


{{0.457427, 1.}, {-1.45743, 1.}}

And I know the mathematica one is correct because it gives the correct graph of the wavefuntion calculated using eigenvectors.

And this is not just a matter of normalization because the numpy result cannot be scaled by a factor to get the correct result.(there are two 1s in mathematica result but there are no two same numbers in our numpy code)

There is a workaround using sympy,but What is the problem and is there a way to get correct eigen vectors in numpy itself?

Asked By: Abhinav P B



Both computations are correct. Numpy gives normalized eigenvectors of length 1. Divide each column of the numpy eigenvector matrix by the second number in the column to get the vectors computed by Mathematica.

import numpy as np

A = np.array([[1,2],[3,4]])
vals, vects = np.linalg.eig(A)


It gives:

[[-0.82456484 -0.41597356]
 [ 0.56576746 -0.90937671]]

Divide by the last row:



[[-1.45742711  0.45742711]
 [ 1.          1.        ]]
Answered By: bb1
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.