Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Pierre GM
On Dec 2, 2009, at 6:55 PM, Howard Chong wrote: My question is: how can I make the latter version run faster? I think the answer is that I have to do the iteration in C. If that's the case, can anyone point me to where np.array.argmax() is implemented so I can write np.array.argmaxN()

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread David Warde-Farley
On 2-Dec-09, at 6:55 PM, Howard Chong wrote: def myFindMaxA(myList): implement finding maximum value with for loop iteration maxIndex=0 maxVal=myList[0] for index, item in enumerate(myList): if item[0]maxVal: maxVal=item[0] maxIndex=index

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Keith Goodman
On Wed, Dec 2, 2009 at 5:09 PM, Neal Becker ndbeck...@gmail.com wrote: David Warde-Farley wrote: On 2-Dec-09, at 6:55 PM, Howard Chong wrote: def myFindMaxA(myList):    implement finding maximum value with for loop iteration    maxIndex=0    maxVal=myList[0]    for index, item in

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread David Warde-Farley
On 2-Dec-09, at 8:09 PM, Neal Becker wrote: Not bad, although I wonder whether a partial sort could be faster. Probably (if the array is large) but depending on n, not if it's in Python. Ideal problem for Cython, though. David ___ NumPy-Discussion

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Anne Archibald
2009/12/2 Keith Goodman kwgood...@gmail.com: On Wed, Dec 2, 2009 at 5:09 PM, Neal Becker ndbeck...@gmail.com wrote: David Warde-Farley wrote: On 2-Dec-09, at 6:55 PM, Howard Chong wrote: def myFindMaxA(myList):    implement finding maximum value with for loop iteration    maxIndex=0    

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Neal Becker
Keith Goodman wrote: ... Not bad, although I wonder whether a partial sort could be faster. I'm doing a lot of sorting right now. I only need to sort the lowest 30% of values in a 1d array (about 250k elements), the rest I don't need to sort. How do I do a partial sort? I only know of it

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Anne Archibald
2009/12/2 David Warde-Farley d...@cs.toronto.edu: On 2-Dec-09, at 8:09 PM, Neal Becker wrote: Not bad, although I wonder whether a partial sort could be faster. Probably (if the array is large) but depending on n, not if it's in Python. Ideal problem for Cython, though. How is Cython

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Keith Goodman
On Wed, Dec 2, 2009 at 5:27 PM, Anne Archibald peridot.face...@gmail.com wrote: 2009/12/2 Keith Goodman kwgood...@gmail.com: On Wed, Dec 2, 2009 at 5:09 PM, Neal Becker ndbeck...@gmail.com wrote: David Warde-Farley wrote: On 2-Dec-09, at 6:55 PM, Howard Chong wrote: def myFindMaxA(myList):

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Anne Archibald
2009/12/2 Keith Goodman kwgood...@gmail.com: On Wed, Dec 2, 2009 at 5:27 PM, Anne Archibald peridot.face...@gmail.com wrote: 2009/12/2 Keith Goodman kwgood...@gmail.com: On Wed, Dec 2, 2009 at 5:09 PM, Neal Becker ndbeck...@gmail.com wrote: David Warde-Farley wrote: On 2-Dec-09, at 6:55 PM,

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Keith Goodman
On Wed, Dec 2, 2009 at 5:52 PM, Anne Archibald peridot.face...@gmail.com wrote: 2009/12/2 Keith Goodman kwgood...@gmail.com: On Wed, Dec 2, 2009 at 5:27 PM, Anne Archibald peridot.face...@gmail.com wrote: 2009/12/2 Keith Goodman kwgood...@gmail.com: On Wed, Dec 2, 2009 at 5:09 PM, Neal Becker

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread David Warde-Farley
On 2-Dec-09, at 8:32 PM, Anne Archibald wrote: 2009/12/2 David Warde-Farley d...@cs.toronto.edu: On 2-Dec-09, at 8:09 PM, Neal Becker wrote: Not bad, although I wonder whether a partial sort could be faster. Probably (if the array is large) but depending on n, not if it's in Python. Ideal

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Keith Goodman
On Wed, Dec 2, 2009 at 5:44 PM, Charles R Harris charlesr.har...@gmail.com wrote: On Wed, Dec 2, 2009 at 6:32 PM, Anne Archibald peridot.face...@gmail.com wrote: 2009/12/2 David Warde-Farley d...@cs.toronto.edu: On 2-Dec-09, at 8:09 PM, Neal Becker wrote: Not bad, although I wonder

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Neal Becker
Keith Goodman wrote: ... Oh, I thought he meant there was a numpy function for partial sorting. Actually, I do use this myself. My code is a boost::python wrapper or the std::partial_sum using pyublas. Here's the main pieces: templatetypename out_t, typename in_t inline out_t partial_sum

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Neal Becker
Neal Becker wrote: Keith Goodman wrote: ... Oh, I thought he meant there was a numpy function for partial sorting. Actually, I do use this myself. My code is a boost::python wrapper or the std::partial_sum using pyublas. Here's the main pieces: templatetypename out_t, typename in_t

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Keith Goodman
On Wed, Dec 2, 2009 at 7:15 PM, Neal Becker ndbeck...@gmail.com wrote: Neal Becker wrote: Keith Goodman wrote: ... Oh, I thought he meant there was a numpy function for partial sorting. Actually, I do use this myself.  My code is a boost::python wrapper or the std::partial_sum using

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Neal Becker
Neal Becker wrote: Keith Goodman wrote: ... Oh, I thought he meant there was a numpy function for partial sorting. Try this one: templatetypename in_t inline void partial_sort (in_t in, int n_el) { std::partial_sort (boost::begin (in), boost::begin(in) + n_el, boost::end (in)); } ...

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Neal Becker
Keith Goodman wrote: On Wed, Dec 2, 2009 at 7:15 PM, Neal Becker ndbeck...@gmail.com wrote: Neal Becker wrote: Keith Goodman wrote: ... Oh, I thought he meant there was a numpy function for partial sorting. Actually, I do use this myself. My code is a boost::python wrapper or the

Re: [Numpy-discussion] Find the N maximum values and corresponding indexes in an array

2009-12-02 Thread Keith Goodman
On Wed, Dec 2, 2009 at 7:31 PM, Neal Becker ndbeck...@gmail.com wrote: Keith Goodman wrote: On Wed, Dec 2, 2009 at 7:15 PM, Neal Becker ndbeck...@gmail.com wrote: Neal Becker wrote: Keith Goodman wrote: ... Oh, I thought he meant there was a numpy function for partial sorting.