Hi Peter & All, On Fri, May 23, 2008 at 4:16 PM, Peter Creasey wrote: > Hi Andrea, > > 2008/5/23 "Andrea Gavana" <[EMAIL PROTECTED]>: >> 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.
Thank you for your answer. I have tried your suggestion, and the performances are more or less comparable with the other NumPy implementations (yours is roughly 1.2 times slower than the others), but I do gain some advantage when the subgrids are very small (i.e., most of the values in the first array are already False). I'll go and implement your solution when I have many small subgrids in my model. Thank you! Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion