ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
[Numpy-discussion] Is sum() slow?
by Mads Ipsen other posts by this author
Mar 6 2006 11:16PM messages near this date
[Numpy-discussion] numpy doc strings - a tool to list problem cases | Re: [Numpy-discussion] Is sum() slow?
Hi,

Sorry if this is a double post - unsure if it made it the first time:

Here are some timings that puzzle me a bit. Sum the two rows of a 2xn
matrix, where n is some large number

python -m timeit -s "from numpy import array,sum,reshape; x =
array([1.5]*1000); x = reshape(x,(2,500))" "x.sum(0)"
10000 loops, best of 3: 36.2 usec per loop

python -m timeit -s "from numpy import array,sum,reshape; x =
array([1.5]*1000); x = reshape(x,(2,500))" "x[0] + x[1]"
100000 loops, best of 3: 5.35 usec per loop

The two calculations are completely equivalent (at least from the
numerical results point of view). But using the built-in sum() function is
app. 6 times slower.

Just for the reference - using Numeric gives

python -m timeit -s "from Numeric import array,sum,reshape; x =
array([1.5]*1000); x = reshape(x,(2,500))" "sum(x)"
100000 loops, best of 3: 7.08 usec per loop

Any suggestions to why this might be - or am I doing something wrong here?

Thanks // Mads

PS. Thanks to everybody that responded to my previous posting on problems
and questions regarding rint() and related coding issues. Your replies
were very helpful!



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Mads Ipsen
Travis Oliphant
Sasha
Alexander Belopolsky

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved