[Numpy-discussion] Multiple Boolean Operations

Peter Creasey p.e.creasey.00@googlemail....
Fri May 23 10:16:11 CDT 2008


Hi Andrea,

2008/5/23  "Andrea Gavana" <andrea.gavana@gmail.com>:
> And so on. The probelm with this approach is that I lose the original
> indices for which I want all the inequality tests to succeed:

To have the original indices you just need to re-index your indices, as it were

idx = flatnonzero(xCent >= xMin)
idx = idx[flatnonzero(xCent[idx] <= xMax)]
idx = idx[flatnonzero(yCent[idx] >= yMin)]
idx = idx[flatnonzero(yCent[idx] <= yMax)]
...
(I haven't tested this code, apologies for bugs)

However, there is a performance penalty for doing all this re-indexing
(I once fell afoul of this), and if these conditions "mostly" evaluate
to True you can often be better off with one of the solutions already
suggested.

Regards,
Peter


More information about the Numpy-discussion mailing list