[Numpy-discussion] sort bug
Thu Apr 26 14:08:15 CDT 2007
Anton Sherwood wrote:
> Travis Oliphant wrote:
>> cmp(x,y) must return -1, 0, or 1 which doesn't work on arrays with more
>> than 1 element because it is ambiguous. Thus you get this error.
> Ah. Since lists *can* be compared, I assumed arrays would inherit
> that property.
>> The operation is undefined. What do you actually want to do when you
>> have equal-valued eigenvalues?
> Don't care.
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)
Will do what you want.
More information about the Numpy-discussion