[Numpy-discussion] efficient summation
dd55 at cornell.edu
Wed Sep 1 21:35:10 EDT 2004
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
Rx = ones((2500,2500))*12.5
N = zeros((2500,2500),typecode=Bool)
trans = compress(N,Rx)
temp = exp(2j*pi*(trans+trans))*exp(2j*pi*(trans))
s = sum(temp.real)
print s, clock()
More information about the NumPy-Discussion