[Numpy-discussion] strange behavior with a numpy array as member of a list

Tim Hirzel hirzel at resonon.com
Thu Nov 30 14:48:38 CST 2006


Thanks Robert.
That makes more sense now.  Although I am still a little puzzled by the 
equality behavior of an array.  for example:

 >>> a = numpy.arange(5)
 >>> None == a
False

 >>> 5 == a
array([False, False, False, False, False], dtype=bool)

 >>> class Empty:
    pass
 >>> e = Empty()
 >>> e == a
array([False, False, False, False, False], dtype=bool)

 >>> L = []
 >>> L == a
False

#this behavior seems consistent regardless of the dtype of the array:
 >>> b = numpy.array([None, 5])
 >>> b
array([None, 5], dtype=object)
 >>> b  == 4
array([False, False], dtype=bool)

What determines if an array tests for equality as the entire array or 
element-wise?

thanks again,
tim



Robert Kern wrote:
> Tim Hirzel wrote:
>   
>> Does this seem odd to anyone else?  I am not sure about the 
>> implementation of 'in' but it seems like a comparison is going funny 
>> somewhere.  Or I am missing something...
>>     
>
> Yes, list.__contains__ uses equality to test for membership, not identity.
>
>   


More information about the Numpy-discussion mailing list