[Numpy-discussion] Multiple Boolean Operations
Nathan Bell
wnbell@gmail....
Thu May 22 15:36:26 CDT 2008
On Thu, May 22, 2008 at 2:16 PM, Andrea Gavana <andrea.gavana@gmail.com> wrote:
> By the way, about the solution Francesc posted:
>
> xyzReq = (xCent >= xMin) & (xCent <= xMax) & \
> (yCent >= yMin) & (yCent <= yMax) & \
> (zCent >= zMin) & (zCent <= zMax)
>
You could implement this with inplace operations to save memory:
xyzReq = (xCent >= xMin)
xyzReq &= (xCent <= xMax)
xyzReq &= (yCent >= yMin)
xyzReq &= (yCent <= yMax)
xyzReq &= (zCent >= zMin)
xyzReq &= (zCent <= zMax)
> Do you think is there any chance that a C extension (or something
> similar) could be faster? Or something else using weave? I understand
> that this solution is already highly optimized as it uses the power of
> numpy with the logic operations in Python, but I was wondering if I
> can make it any faster
A C implementation would certainly be faster, perhaps 5x faster, due
to short-circuiting the AND operations and the fact that you'd only
pass over the data once.
OTOH I'd be very surprised if this is the slowest part of your application.
--
Nathan Bell wnbell@gmail.com
http://graphics.cs.uiuc.edu/~wnbell/
More information about the Numpy-discussion
mailing list