[Numpy-discussion] sort bug

Charles R Harris charlesr.harris@gmail....
Sun Apr 29 00:11:29 CDT 2007


On 4/28/07, Anton Sherwood <bronto@pobox.com> wrote:
>
> Travis Oliphant wrote:
> > One approach is to use argsort to create an index list of sorted
> > eigenvalues and then sort the eig and eigvector arrays before zipping
> > them together in a list of tuples.
> >
> > eig, val = numpy.linalg.eig(a)
> >
> > indx = eig.argsort()
> > eig = eig.take(indx)
> > val = val.take(indx, axis=1)
> > master = zip(eig, val.T)
>
> Thank you, that worked.
> http://www.ogre.nu/wp/?p=1978
>
> I refined it slightly:
>
> val,vec = numpy.linalg.eig(adj)
> indx = val.argsort()[-4:-1]
> val = val.take(indx)
> vec = vec.take(indx, axis=1)
> master = zip(val, vec.T)


But that won't get the 4  largest, and will ignore the last eigenvalue,
whatever it is. If you want the four largest, do

val,vec =  numpy.linalg.eig(adj)
ind = val.argsort()
val = val.take(ind[-4:])
vec = vec.take(ind[-4:], axis=1)
master = zip(val, vec.T)

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070428/94b2f3bb/attachment-0001.html 


More information about the Numpy-discussion mailing list