logo       

efficient summation: msg#00003

python.numeric.general

Subject: efficient summation

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



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise