Re: [Numpy-discussion] sum of positive values in an array

2008-09-07 Thread Michael McNeil Forbes
On Sep 5, 2008, at 8:52 AM, Keith Goodman wrote: > Here's another difference: > >>> a = np.random.randn(10) >>> timeit np.sum(a[np.where(a>0)]) > 100 loops, best of 3: 3.44 ms per loop >>> timeit a[a > 0].sum() > 100 loops, best of 3: 2.21 ms per loop Here is an even faster method (but much m

Re: [Numpy-discussion] sum of positive values in an array

2008-09-07 Thread Michael McNeil Forbes
On Sep 5, 2008, at 8:52 AM, Keith Goodman wrote: > Here's another difference: > >>> a = np.random.randn(10) >>> timeit np.sum(a[np.where(a>0)]) > 100 loops, best of 3: 3.44 ms per loop >>> timeit a[a > 0].sum() > 100 loops, best of 3: 2.21 ms per loop Here is an even faster method (but much m

Re: [Numpy-discussion] sum of positive values in an array

2008-09-05 Thread SimonPalmer
thank you very much, deliciously satisfying On Sep 5, 3:33 pm, Zachary Pincus <[EMAIL PROTECTED]> wrote: > > Hi, probably a basic question, but I'm looking for a neat way to sum > > all the positive values in an array of floats.  I'm currently doing it > > the hard way, but am hoping there is some

Re: [Numpy-discussion] sum of positive values in an array

2008-09-05 Thread Keith Goodman
On Fri, Sep 5, 2008 at 9:08 AM, David Cournapeau <[EMAIL PROTECTED]> wrote: > On Fri, Sep 5, 2008 at 11:52 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > >> Here's another difference: >> a = np.random.randn(10) timeit np.sum(a[np.where(a>0)]) >> 100 loops, best of 3: 3.44 ms per loop

Re: [Numpy-discussion] sum of positive values in an array

2008-09-05 Thread David Cournapeau
On Fri, Sep 5, 2008 at 11:52 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > Here's another difference: > >>> a = np.random.randn(10) >>> timeit np.sum(a[np.where(a>0)]) > 100 loops, best of 3: 3.44 ms per loop >>> timeit a[a > 0].sum() > 100 loops, best of 3: 2.21 ms per loop But you're not c

Re: [Numpy-discussion] sum of positive values in an array

2008-09-05 Thread Keith Goodman
On Fri, Sep 5, 2008 at 7:32 AM, David Cournapeau <[EMAIL PROTECTED]> wrote: > Ludwig wrote: >> What are the relative merits of >> >> sum(a[where(a>0]) >> >> to >> >> a[a > 0].sum() >> >> ? >> Second one is more OO, takes a few keystrokes less to type. Is there >> any real difference if it came to v

Re: [Numpy-discussion] sum of positive values in an array

2008-09-05 Thread David Cournapeau
Ludwig wrote: > What are the relative merits of > > sum(a[where(a>0]) > > to > > a[a > 0].sum() > > ? > Second one is more OO, takes a few keystrokes less to type. Is there > any real difference if it came to very large arrays? Or is it 'just' a > style question? In this case, it is style: sum(

Re: [Numpy-discussion] sum of positive values in an array

2008-09-05 Thread Ludwig
What are the relative merits of sum(a[where(a>0]) to a[a > 0].sum() ? Second one is more OO, takes a few keystrokes less to type. Is there any real difference if it came to very large arrays? Or is it 'just' a style question? Ludwig 2008/9/5 Zachary Pincus <[EMAIL PROTECTED]> > > > > Hi, pro

Re: [Numpy-discussion] sum of positive values in an array

2008-09-05 Thread Zachary Pincus
> > Hi, probably a basic question, but I'm looking for a neat way to sum > all the positive values in an array of floats. I'm currently doing it > the hard way, but am hoping there is some cunning and elegant syntax I > can use instead Fancy indexing's my favorite cunning and elegant syntax: a =

[Numpy-discussion] sum of positive values in an array

2008-09-05 Thread SimonPalmer
Hi, probably a basic question, but I'm looking for a neat way to sum all the positive values in an array of floats. I'm currently doing it the hard way, but am hoping there is some cunning and elegant syntax I can use instead ___ Numpy-discussion mailing