[Numpy-discussion] np.in1d() & sets, bug?

Sebastian Berg sebastian at sipsolutions.net
Mon Aug 10 13:10:04 EDT 2015


On Mo, 2015-08-10 at 12:09 -0400, Benjamin Root wrote:
> Just came across this one today:
> 
> >>> np.in1d([1], set([0, 1, 2]), assume_unique=True)
> array([ False], dtype=bool)
> 
> >>> np.in1d([1], [0, 1, 2], assume_unique=True)
> 
> array([ True], dtype=bool)
> 
> 
> I am assuming this has something to do with the fact that order is not
> guaranteed with set() objects? I was kind of hoping that setting
> "assume_unique=True" would be sufficient to overcome that problem.
> Should sets be rejected as an error?
> 

Not really, it is "simply" because ``np.asarray(set([1, 2, 3]))``
returns an object array and 1 is not the same as ``set([1, 2, 3])``.

I think earlier numpy versions may have had "short cuts" for short lists
or something so this may have worked in some cases....

- Sebastian


> 
> This was using v1.9.0
> 
> 
> Cheers!
> 
> Ben Root
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150810/1927b9b2/attachment.sig>


More information about the NumPy-Discussion mailing list