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

Alan G Isaac aisaac@american....
Thu Jun 4 10:19:49 CDT 2009


On 6/4/2009 10:50 AM josef.pktd@gmail.com apparently wrote:
> intersect1d gives set intersection if both arrays have 
> only unique elements (i.e. are sets).  I thought the 
> naming is pretty clear:

> intersect1d(a,b)   set intersection if a and b with unique elements 
> intersect1d_nu(a,b)   set intersection if a and b with non-unique elements 
> setmember1d(a,b)  boolean index array for a of set intersection if a 
> and b with unique elements 
> setmember1d_nu(a,b)  boolean index array for a of set intersection if 
> a and b with non-unique elements 


>>> a
array([1, 1, 2, 3, 3, 4])
>>> b
array([1, 4, 4, 4])
>>> np.intersect1d_nu(a,b)
array([1, 4])

That is, intersect1d_nu is the actual set intersection
function.  (I.e., intersect1d and intersect1d_nu would most
naturally have swapped names.)  That is why the appended _nu
will not communicate what was intended.  (I.e.,
setmember1d_nu will not be a match for intersect1d_nu.)

Cheers,
Alan Isaac




More information about the Numpy-discussion mailing list