# [SciPy-user] Proper Use of NumPy's eig()

Nils Wagner nwagner@iam.uni-stuttgart...
Wed Feb 28 02:37:24 CST 2007

```Robert Kern wrote:
> Rich Shepard wrote:
>
>
>>    However, I don't see the answer I expected. My expectation is that all
>> values would be in the range [0.00-1.00], but they're not.
>>
>>    When I print eigE I see:
>>
>> (array([  8.88174744e+00+0.j        ,   3.54286503e-01+2.48721395j,
>>           3.54286503e-01-2.48721395j,  -3.11162331e-01+1.00980412j,
>>          -3.11162331e-01-1.00980412j,  -2.79755841e-01+0.46954619j,
>>          -2.79755841e-01-0.46954619j,  -4.08484096e-01+0.j        ]),
>> array([[  6.24249034e-01 +0.00000000e+00j,
>>
>
> ...
>
> Without knowing your input, I can't see anything particularly wrong. Unless if E
> were real-symmetric (or complex-Hermitian), you are likely to end up with
> complex eigenvalues.
>
>
>>    Since eig(E) "Return[s] all solutions (lamda, x) to the equation Ax =
>> lamda x. The first element of the return tuple contains all the eigenvalues.
>> The second element of the return tuple contains the eigenvectors in the
>> columns (x[:,i] is the ith eigenvector)."
>>
>>    I can't interpret the above. If the first tuple has all the Eigenvalues,
>> how do I extract the principal Eigenvector from the rest? When I did this
>> manually a couple of years ago, I used Octave to calculate the principal
>> Eigenvector and the answer was easy for me to see.
>>
>
> I don't think that the notion of a principal eigenvector is well-defined if the
> matrix is not symmetric. But if you do have a symmetric matrix:
>
>
> import numpy as np
> from scipy import linalg
>
> eigvals, eigvecs = linalg.eig(E)
> i = np.real_if_close(eigvals).argmax()
> principal_eigvec = eigvecs[:, i]
>
>

Hi Rich,

here is another approach to compute the principal eigenpair (absil.py)

Nils

-------------- next part --------------
A non-text attachment was scrubbed...
Name: absil.py
Type: text/x-python
Size: 1019 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-user/attachments/20070228/c9a72330/attachment.py
```