Re: [Numpy-discussion] cumsum much slower than simple loop?

2012-02-10 Thread Pauli Virtanen
10.02.2012 05:39, Dave Cook kirjoitti: Why is numpy.cumsum (along axis=0) so much slower than a simple loop? The same goes for numpy.add.accumulate The reason is loop ordering. The reduction operator when using `cumsum` or `add.reduce` does the summation in the inmost loop, whereas the

[Numpy-discussion] cumsum much slower than simple loop?

2012-02-09 Thread Dave Cook
Why is numpy.cumsum (along axis=0) so much slower than a simple loop? The same goes for numpy.add.accumulate # cumsumtest.py import numpy as np def loopcumsum(a): csum = np.empty_like(a) s = 0.0 for i in range(len(a)): csum[i] = s = s + a[i] return csum npcumsum =

Re: [Numpy-discussion] cumsum much slower than simple loop?

2012-02-09 Thread josef . pktd
On Thu, Feb 9, 2012 at 11:39 PM, Dave Cook dav...@gmail.com wrote: Why is numpy.cumsum (along axis=0) so much slower than a simple loop?  The same goes for numpy.add.accumulate # cumsumtest.py import numpy as np def loopcumsum(a):     csum = np.empty_like(a)     s = 0.0     for i in

Re: [Numpy-discussion] cumsum much slower than simple loop?

2012-02-09 Thread Dave Cook
On Thu, Feb 9, 2012 at 9:21 PM, josef.p...@gmail.com wrote: strange (if I didn't make a mistake) In [12]: timeit a.cumsum(0) 100 loops, best of 3: 7.17 ms per loop In [13]: timeit a.T.cumsum(-1).T 1000 loops, best of 3: 1.78 ms per loop In [14]: (a.T.cumsum(-1).T == a.cumsum(0)).all()

Re: [Numpy-discussion] cumsum much slower than simple loop?

2012-02-09 Thread Elliot Saba
numpy 1.6.1, OSX, Core 2 Duo: In [7]: timeit a.cumsum(0) 100 loops, best of 3: 6.67 ms per loop In [8]: timeit a.T.cumsum(-1).T 100 loops, best of 3: 6.75 ms per loop -E On Thu, Feb 9, 2012 at 9:51 PM, Dave Cook dav...@gmail.com wrote: On Thu, Feb 9, 2012 at 9:41 PM, Dave Cook