python 3.x - NumPy: difference between linalg.eig() and linalg.eigh()

python 3.x – NumPy: difference between linalg.eig() and linalg.eigh()

python 3.x – NumPy: difference between linalg.eig() and linalg.eigh()

eigh guarantees you that the eigenvalues are sorted and uses a faster algorithm that takes advantage of the fact that the matrix is symmetric. If you know that your matrix is symmetric, use this function.
Attention, eigh doesnt check if your matrix is indeed symmetric, it by default just takes the lower triangular part of the matrix and assumes that the upper triangular part is defined by the symmetry of the matrix.

eig works for general matrices and therefore uses a slower algorithm, you can check that for example with IPythons magic command %timeit. If you test with larger matrices, you will also see that in general the eigenvalues are not sorted here.

python 3.x – NumPy: difference between linalg.eig() and linalg.eigh()

Related posts on python  :

Leave a Reply

Your email address will not be published.