rocksNwaves
rocksNwaves

Reputation: 6164

When are the eigenvalues returned by numpy.linalg.eig ordered?

The documentation says of the returned values:

The eigenvalues are not necessarily ordered...

But every time I use the function they are in decreasing order, which is perfect for my use. I want to know under what circumstances I will have to make sure that I sort them myself.

Upvotes: 1

Views: 569

Answers (1)

Gianluca
Gianluca

Reputation: 546

If the matrix to be diagonalized is not Hermitian, the eigenvalues will generally be complex, so that they cannot be sorted at all.

numpy.linalg.eig calls LAPACK routines, and in LAPACK sorting in descending order (when possible, i.e. in the case of real eigenvalues) is 'popular convention'. numpy cannot only be linked against the reference LAPACK at http://www.netlib.org/lapack/, but also against any other library providing the corresponding linear algebra routines, which wouldn't necessarily have to perform the same or any eigenvalue sorting. numpy.linalg.eig doesn't perform any sorting beyond what the Fortran routines in LAPACK already perform, hence sorted eigenvalues might not be guaranteed even for Hermitian (including real symmetric) matrices.

Upvotes: 3

Related Questions