4

When I use numpy.linalg.eig like

eValues, eVectors = numpy.linalg.eig(someMatrix)

the eValues returned are almost in descending order.

How does numpy.linalg.eig decide on order in which eigenvalues are returned?

user3731622
  • 4,844
  • 8
  • 45
  • 84

1 Answers1

3

Numpy makes no guarantees about that -

from the docstring:

Returns
-------
w : (..., M) array
    The eigenvalues, each repeated according to its multiplicity.
    The eigenvalues are not necessarily ordered. The resulting
    array will be always be of complex type. When `a` is real
    the resulting eigenvalues will be real (0 imaginary part) or
    occur in conjugate pairs

Numpy delegates to LAPACK for this computation, so if there is any consistent ordering you should consider it implementation detail and not rely on it.

wim
  • 338,267
  • 99
  • 616
  • 750
  • 1
    Ok, I will not rely on it. However, I'm very curious why they seem to almost be in order. If there was really nothing going on to at least kind of order them, then I would expect a more random ordering. – user3731622 May 22 '15 at 17:11
  • I would guess lapack would implement this with row-reduction, so it could be a side-effect of that algorithm? Dig around in the sources if you can read fortran :) – wim May 23 '15 at 05:12