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

Neil Crighton neilcrighton@gmail....
Sat Jun 6 03:42:58 CDT 2009


Robert Cimrman <cimrman3 <at> ntc.zcu.cz> writes:

> Anne Archibald wrote:
>
> > 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
> > 
> 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.
> 

+1 - from the user's point of view there should just be intersect1d and
setmember1d (i.e. no '_nu' versions). The assume_unique keyword Robert suggests
can be used if speed is a problem.

I really like in1d (no underscore) as a new name for setmember1d_nu. inarray is
another possibility. I don't like 'ain'; 'a' in front of 'in' detracts from 
readability, unlike the extra a in arange.

Can we summarise the discussion in this thread and write up a short proposal
about what we'd like to change in arraysetops, and how to make the changes? 
Then it's easy for other people to give their opinion on any changes. I can do
this if no one else has time.


Neil




More information about the Numpy-discussion mailing list