[Numpy-discussion] Multiple Boolean Operations
Christopher Barker
Chris.Barker at noaa.gov
Thu May 22 15:40:41 EDT 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.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
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
Chris.Barker at noaa.gov
More information about the NumPy-Discussion
mailing list