On Sep 5, 2008, at 8:52 AM, Keith Goodman wrote: > Here's another difference: > >>> a = np.random.randn(100000) >>> 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 more ugly!): 0.25ms: (a.sum() + abs(a).sum())/2 0.34ms: a[a > 0].sum() 0.55ms: np.sum(a[np.where(a>0)]) Michael. _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion