[SciPy-user] sorting arrays with complex numbers

Robert Kern rkern at ucsd.edu
Mon Sep 12 19:47:09 CDT 2005


Chris Fonnesbeck wrote:
> This may not be the appropriate place to post this question, but I'm
> sure someone has the answer. I am trying to extract the eigenvector
> with the largest corresponding eigenvalue from an array of
> eigenvectors. As you would expect, the array of eigenvalues contains
> complex numbers:
> 
>>>>d
> 
> array([ 0.6       +0.j        , -0.16037672+0.27778062j,
>             -0.16037672-0.27778062j,  0.32075343+0.j        ])
> 
> When I try and call max() on this array, I get the following error:
> 
>>>>max(d)
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: no ordering relation is defined for complex numbers
> 
> What is the appropriate method for extracting the maximum value from this array?

d[argmax(absolute(d))]

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the SciPy-user mailing list