[Numpy-discussion] extract elements of an array that are contained in another array?

Robert Cimrman cimrman3 at ntc.zcu.cz
Fri Jun 5 01:35:46 EDT 2009


Anne Archibald wrote:
> 2009/6/4  <josef.pktd at gmail.com>:
> 
>> intersect1d should throw a domain error if you give it arrays with
>> non-unique elements, which is not done for speed reasons
> 
> It seems to me that this is the basic source of the problem. Perhaps
> this can be addressed? I realize maintaining compatibility with the
> current behaviour is necessary, so how about a multistage deprecation:
> 
> 1. add a keyword argument to intersect1d "assume_unique"; if it is not
> present, check for uniqueness and emit a warning if not unique
> 2. change the warning to an exception
> Optionally:
> 3. change the meaning of the function to that of intersect1d_nu if the
> keyword argument is not present
> 
> One could do something similar with setmember1d.
> 
> This would remove the pitfall of the 1d assumption and the wart of the
> _nu names without hampering performance for people who know they have
> unique arrays and are in a hurry.

You mean something like:

def intersect1d(ar1, ar2, assume_unique=False):
     if not assume_unique:
         return intersect1d_nu(ar1, ar2)
     else:
         ... # the current code

intersect1d_nu could be still exported to numpy namespace, or not.

I like this. I do not undestand, however, what you mean by "remove the 
pitfall of the 1d assumption"?

cheers,
r.




More information about the NumPy-Discussion mailing list