[Numpy-discussion] Multiple Boolean Operations

Christopher Barker Chris.Barker@noaa....
Thu May 22 14:40:41 CDT 2008

Andrea Gavana wrote:
> By the way, about the solution Francesc posted:
> xyzReq = (xCent >= xMin) & (xCent <= xMax) &  \
>             (yCent >= yMin) & (yCent <= yMax) &  \
>             (zCent >= zMin) & (zCent <= zMax)
> xyzReq = numpy.nonzero(xyzReq)[0]
> Do you think is there any chance that a C extension (or something
> similar) could be faster?

yep -- if I've be got this right, the above creates 7 temporary arrays. 
creating that many and pushing the data in and out of memory can be 
pretty slow for large arrays.

In C, C++, Cython or Fortran, you can just do one loop, and one output 
array. It should be much faster for the big arrays.

> Otherwise, I will try and implement it in Fortran and wrap it with
> f2py, assuming I am able to do it correctly and the overhead of
> calling an external extension is not killing the execution time.

nope, that's one function call for the whole thing, negligible.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list