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.
#------------

Johannes
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to