On 7/18/06, Eric Emsellem <[EMAIL PROTECTED]> wrote: [...] > (is "sum" different than "add.reduce"?)
"sum" is a wrapper around ndarray.sum method, while add.reduce is a ufunc method. At the C level they are the same, but "sum" may be a little slower for the small arrays. > python -m timeit -s "from numpy import add, zeros, sum; x = zeros(10)" > "sum(x)" 100000 loops, best of 3: 5.53 usec per loop > python -m timeit -s "from numpy import add, zeros, sum; x = zeros(10)" > "add.reduce(x)" 100000 loops, best of 3: 2.71 usec per loop In the new code, I would recommend using the ndarray.sum method instead of either of the two. BTW, is this an optimization opportunity: compare > python -m timeit -s "from numpy import add, zeros, sum; x = zeros(10); > r=add.reduce" "r(x)" 100000 loops, best of 3: 2.55 usec per loop and > python -m timeit -s "from numpy import zeros; x = zeros(10)" "x.sum()" 100000 loops, best of 3: 3.88 usec per loop ? ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion