On Tue, Jul 19, 2011 at 07:38, Andrea Cimatoribus <g.plantagen...@gmail.com> wrote: > Dear all, > I would like to avoid the use of a boolean array (mask) in the following > statement: > > mask = (A != 0.) > B = A[mask] > > in order to be able to move this bit of code in a cython script (boolean > arrays are not yet implemented there, and they slow down execution a lot as > they can't be defined explicitely). > Any idea of an efficient alternative?
You will have to count the number of True values, create the B array with the right size, then run a simple loop to assign into it where A != 0. This makes you do the comparisons twice. Or you can allocate a B array the same size as A, run your loop to assign into it when A != 0 and incrementing the index into B, then slice out or memcpy out the portion that you assigned. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion