logo       

Re: efficient summation: msg#00006

python.numeric.general

Subject: Re: efficient summation

Stephen Walton wrote:

In addition, I doubt you can measure CPU time for only a 10 element
array. I had to use 1e7 elements in MATLAB on a 2.26MHz P4 just to get
the CPU time large enough to measure reasonably accurately. Also recall
that it is a known characteristic of numarray that it is slow on small
arrays in general.


Sorry, I was giving the 10 element example for clarity. I am actually using arrays with over 6e6 elements.

I just discovered compress, it works wonders in my situation.
The following script runs in 1 second on my 2GHz P4, winXP. The same calculation using a masked array took 18 seconds:

from numarray import *
from time import clock

clock()
Rx = ones((2500,2500))*12.5
N = zeros((2500,2500),typecode=Bool)
N[:250,:]=1
trans = compress(N,Rx)
temp = exp(2j*pi*(trans+trans))*exp(2j*pi*(trans))
s = sum(temp.real)
print s, clock()



-------------------------------------------------------
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