[Numpy-discussion] linalg.eigh orders eigenvalues/eigenvectors differently than linalg.eig

Johannes Loehnert a.u.r.e.l.i.a.n@gmx....
Mon Feb 19 06:14:50 CST 2007

On Monday 19 February 2007 12:06, Sven Schreiber wrote:
> Zachary Pincus schrieb:
> > Hello all,
> >
> > It seems that the 'eigh' routine from numpy.linalg does not follow
> > the same convention as numpy.linalg.eig in terms of the order of the
> > returned eigenvalues. (And thus eigenvectors as well...)
> I was told on this list that the ordering should not be relied upon, and
> that it might change in the future. So it seems that user code should
> explicitly re-order the eigenvalues (and corresponding eigenvectors,
> probably using argsort and fancy indexing -- if those are the right terms).

Indeed. eig and eigh are wrappers for lapack functions, so the result is 
whatever those give back. Do not rely on a particular order of eigenvalues, 
sort yourself.

Short example for convenience:
eigvals, eigvecs = eig(some_matrix)
ind = argsort(eigvals)
eigvals = eigvals[ind]
eigvecs = eigvecs[:, ind]   # second axis !!
# etc.


More information about the Numpy-discussion mailing list