[Numpy-discussion] extract elements of an array that are contained in another array?
Alan G Isaac
Thu Jun 4 11:32:33 CDT 2009
On 6/4/2009 11:29 AM firstname.lastname@example.org apparently wrote:
> intersect1d is the intersection between sets (which are stored as
> arrays), just like in the mathematical definition the two sets only
> have unique elements
Hmmm. OK, I see you and Robert believe this.
But it does not match the documentation.
But indeed, I see that the documentation is incorrect.
array([1, 1, 3, 4])
Is this a bug or a documentation bug?
> intersect1d_nu is the intersection between two arrays which can have
> repeated elements. The result is a set, i.e. unique elements, stored
> as an array
> same for setmember1d, setmember1d_nu
I cannot understand this.
Following your proposed reasoning,
I expect a[setmember1d_nu(a,b)]
to return the same as
It does not.
> so postfix `_nu` only means that this function also works
> if the two arrays are not really sets
But that just begs the question: what does 'works' mean?
See my previous comment (above).
> intersect1d should throw a domain error if you give it arrays with
> non-unique elements, which is not done for speed reasons
*If* intersect1d behaved *exactly* as documented,
shows that the documented behavior can be useful.
And indeed, this would be the match to
More information about the Numpy-discussion