Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are these 2 ways of finding eigenvectors different in python?

import numpy as np
#first way
A = np.array([[1, 0, 1], [-2, 1, 0]])
print(A)
B = [email protected]()
print(B)
eig_val, eig_vec = np.linalg.eig(B)
print(eig_vec)

#second way
from sympy import * 
G = Matrix([[2,-2], [-2,5]])
print(G.eigenvects())

Why does these two ways give different result when they are aiming a same goal of finding the eigenvectors?

like image 732
strike counter Avatar asked Mar 21 '26 18:03

strike counter


1 Answers

It has already been mentioned that eignevectors are only unique upto a scalar multiple. That's a mathematical fact. To dig into the implementations of the methods you're using, numpy.linalg.eig returns normalized eigenvectors (i.e. the norm of the vectors would be 1) whereas eigenvects() of sympy does not normalize the vectors.

In some sense, normalized vectors are unique precisely because they have unit norm. They can define a unit eigendirection (geometrically), just like unit vectors in coordinate geometry. (Not strictly important to know)

like image 78
amzon-ex Avatar answered Mar 23 '26 06:03

amzon-ex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!