[Numpy-discussion] extract elements of an array that are contained in another array?
Robert Cimrman
cimrman3 at ntc.zcu.cz
Thu Jun 4 11:27:11 EDT 2009
Alan G Isaac wrote:
> On 6/4/2009 10:50 AM josef.pktd at 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.)
The naming should express this: intersect1d expects its arguments are
sets, intersect1d_nu does not. A set has unique elements by definition.
cheers,
r.
More information about the NumPy-Discussion
mailing list