[Numpy-discussion] setmember1d memory leak?

Robert Kern robert.kern at gmail.com
Wed Jan 24 04:04:03 CST 2007


Robert Cimrman wrote:
> 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
> 'arraymember'.

Oh yes, certainly. I think all of the functions in arraysetops should remain set
operations. Other functionality will go elsewhere. I was simply pointing out
that Jan and Per are specifically asking for other functionality.

> 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.

Yup.

-- 
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


More information about the Numpy-discussion mailing list