[SciPy-Dev] replacing integrate.cumtrapz with numpy.trapz
Alan G Isaac
aisaac at american.edu
Sat Jul 17 11:17:16 EDT 2010
On Sat, Jul 17, 2010 at 2:42 AM, Ralf Gommers <mailto:ralf.gommers at googlemail.com> wrote:
> For a small bonus, the numpy version is about 10% faster
> (tested for several array shapes):
> >>> a = np.arange(1e4).reshape(500, 20)
> >>> %timeit np.trapz(a, axis=1)
> 10000 loops, best of 3: 182 us per loop
> >>> %timeit sp.integrate.cumtrapz(a, axis=1)
> 1000 loops, best of 3: 209 us per loop
That reminds me of a question:
numpy.trapz returns
add.reduce(d * (y[slice1]+y[slice2])/2.0,axis)
Isn't that equivalent to but slightly less efficient than
(d * (y[slice1]+y[slice2])).sum(axis=axis)/2.0
?
Alan Isaac
More information about the SciPy-Dev
mailing list