Re: [Numpy-discussion] sort bug

2007-05-02 Thread Nils Wagner
mark wrote: > Sorry for joining this discussion late. > If you are only interested in the four largest eigenvalues, there are > more efficient algorithms out there than just eig(). > There are algorithms that just give you the N largest. > Then again, I don't know of any Python implementations, but

Re: [Numpy-discussion] sort bug

2007-05-02 Thread mark
Sorry for joining this discussion late. If you are only interested in the four largest eigenvalues, there are more efficient algorithms out there than just eig(). There are algorithms that just give you the N largest. Then again, I don't know of any Python implementations, but I haven't looked, Mar

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Matthieu Brucher
2007/4/29, Anton Sherwood <[EMAIL PROTECTED]>: > Anton Sherwood wrote: > > I'm using eigenvectors of a graph's adjacency matrix as "topological" > > coordinates of the graph's vertices as embedded in 3space (something I > > learned about just recently). Whenever I've done this with a graph that

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Anton Sherwood
> Anton Sherwood wrote: > > I'm using eigenvectors of a graph's adjacency matrix as "topological" > > coordinates of the graph's vertices as embedded in 3space (something I > > learned about just recently). Whenever I've done this with a graph that > > *does* have a good 3d embedding, using the fi

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Charles R Harris
On 4/29/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: > Anton Sherwood wrote: > 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) Charles R Harris wrot

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Robert Kern
Anton Sherwood wrote: >> Anton Sherwood wrote: >> 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) > > Charles R Harris wrote: >> But that won't ge

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Anton Sherwood
> Anton Sherwood wrote: > 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) Charles R Harris wrote: > But that won't get the 4 largest, and will ignore

Re: [Numpy-discussion] sort bug

2007-04-28 Thread Charles R Harris
On 4/28/07, Anton Sherwood <[EMAIL PROTECTED]> 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

Re: [Numpy-discussion] sort bug

2007-04-28 Thread Anton Sherwood
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.t

Re: [Numpy-discussion] sort bug

2007-04-26 Thread tan2
Just doing argsort() on the whole array is faster (up until about 1e6 elements) because it does everything in C whereas heapq will create a lot of Python objects because it is treating the array as a general Python container. That's a good point. I wasn't thinking about the efficiency issue. _

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Robert Kern
tan2 wrote: > > On 4/26/07, * Anton Sherwood* <[EMAIL PROTECTED] > > wrote: > > All I really need is the four highest eigenvalues and their > vectors. > I'll have a look in "Python Cookbook" to see if there's a more > efficient way

Re: [Numpy-discussion] sort bug

2007-04-26 Thread tan2
On 4/26/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: > > > All I really need is the four highest eigenvalues and their vectors. > I'll have a look in "Python Cookbook" to see if there's a more > efficient way to do that partial sort. Maybe "heapq.nlargest()" is what you want? http://www.pyt

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Anne Archibald
On 26/04/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: > All I really need is the four highest eigenvalues and their vectors. It's not really very efficient, but sorting time is going to be tiny compared to however you get your eigenvalues, so you could argsort the eigenvalue array and use the re

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Charles R Harris
On 4/26/07, Anton Sherwood <[EMAIL PROTECTED]> 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 prop

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Travis Oliphant
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. > >

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Anton Sherwood
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 actuall

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Travis Oliphant
Anton Sherwood wrote: > This code -- > > adj = [ [eval(y) for y in x.split()] for x in infile ] > val,vec = numpy.linalg.eig(adj) > master = zip( val, vec.transpose() ) > master.sort() > > *sometimes* gives this error: > > Traceback (most recent call last): > F

[Numpy-discussion] sort bug

2007-04-25 Thread Anton Sherwood
This code -- adj = [ [eval(y) for y in x.split()] for x in infile ] val,vec = numpy.linalg.eig(adj) master = zip( val, vec.transpose() ) master.sort() *sometimes* gives this error: Traceback (most recent call last): File "3work.py", line 14, in