[Numpy-discussion] numexpr does sum.
Tim Hochberg
tim.hochberg at cox.net
Tue Jun 27 15:08:13 CDT 2006
I managed to get basic support for sum and prod into numpexpr. I need to
tie up some loose ends, for instance only floats are currently
supported, but these should be easy. To return to the recently posted
multidimensional distance program, this now works:
expr = numexpr("sum((a - b)**2, axis=2)", [('a', float), ('b', float)])
def dist_numexpr(A, B):
return sqrt(expr(A[:,newaxis], B[newaxis,:]))
It's also quite fast, although there's still room for improvement in the
reduction code. Notice that it still needs to be in two parts since
sum/prod needs to surround the rest of the expression. Note also that it
does support the axis keyword, although currently only nonnegative
values (or None). I plan to fix that at some point though.
-tim
More information about the Numpy-discussion
mailing list