[Numpy-discussion] efficient summation
Darren Dale
dd55 at cornell.edu
Wed Sep 1 14:52:04 CDT 2004
I am trying to effieciently sum over a subset of the elements of a
matrix. In Matlab, this could be done like:
a=[1,2,3,4,5,6,7,8,9,10]
b = [1,0,0,0,0,0,0,0,0,1]
res=sum(a(b)) %this sums the elements of a which have corresponding
elements in b that are true
Is there anything similar in numarray (or numeric)? I thought masked
arrays looked promising, but I find that masking 90% of the elements
results in marginal speedups (~5%, instead of 90%) over the unmasked array.
Thanks!
Darren
More information about the Numpy-discussion
mailing list