[Numpy-discussion] setmember1d memory leak?

Robert Cimrman cimrman3 at ntc.zcu.cz
Wed Jan 24 04:45:29 EST 2007

Robert Kern wrote:
> Robert Cimrman wrote:
>> Or you could just call unique1d prior to your call to setmember1d - it
>> was meant to be used that way... you would not loose much speed that
>> way, IMHO.
> But that doesn't do what they want. They want a function that gives the mask
> against their original array of the elements that are in the other array. The
> result of
>   setmember1d(unique1d(ar1), unique1d(ar2))
> is a mask against
>   unique1d(ar1)
> not
>   ar1
> as they want.

I see. I was thinking in terms of 'set member' - in set one assumes
unique elements. A good name for this kind of function would be

Naive pseudo-implementation:

import numpy as nm
def arraymember1d( ar1, ar2 ):

    ar = ar2.copy().sort()
    indx = findsorted( ar2, ar1 )
    flag = nm.zeros( ar1.shape, dtype = nm.bool )
    flag[indx] = True

    return flag

Note that nm.searchsorted cannot be used here - a new function
('findsorted'?) would be needed.


More information about the NumPy-Discussion mailing list