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

2007-02-19 Thread Zachary Pincus
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...)

Specifically, eig returns eigenvalues in order from largest to  
smallest, while eigh returns them from smallest to largest.

Example:
  a = numpy.array([[21, 28, 35],[28, 38, 48],[35, 48, 61]])
  numpy.linalg.eigh(a)
(array([ -1.02825542e-14,   7.04131679e-01,   1.19295868e+02]),
array([[ 0.40824829, -0.81314396, -0.41488581],
[-0.81649658, -0.12200588, -0.56431188],
[ 0.40824829,  0.56913221, -0.71373795]]))

  numpy.linalg.eig(a)
(array([  1.19295868e+02,   7.04131679e-01,   4.62814557e-15]),
array([[-0.41488581, -0.81314396,  0.40824829],
[-0.56431188, -0.12200588, -0.81649658],
[-0.71373795,  0.56913221,  0.40824829]]))

Is this a bug? If it is, though, fixing it now might break code that  
depends on this 'wrong' order. (This is also present in  
scipy.linalg.) If not a bug, or not-fixable-now, then at least some  
documentation as to the convention regarding ordering of eigenvalues  
is probably worthwhile...

Any thoughts?

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


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

2007-02-19 Thread Sven Schreiber
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).

...

 scipy.linalg.) If not a bug, or not-fixable-now, then at least some  
 documentation as to the convention regarding ordering of eigenvalues  
 is probably worthwhile...
 

true

cheers,
sven

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


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

2007-02-19 Thread Johannes Loehnert
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