[Numpy-discussion] equality of empty arrays

Ian Goodfellow goodfellow.ian@gmail....
Mon Oct 11 20:04:51 CDT 2010


If the arrays are the same size or can be broadcasted to the same  
size, it returns true or false on an elementwise basis.
If the arrays are not the same size and can't be broadcasted to the  
same size, it returns False, which was a surprise to me too.

 >>> import numpy as N
 >>> N.asarray([[0,1],[2,3]]) == N.asarray([[1,1],[3,3]])
array([[False,  True],
        [False,  True]], dtype=bool)
 >>> N.asarray([[0,1],[2,3]]) == N.asarray([[1,1]])
array([[False,  True],
        [False, False]], dtype=bool)
 >>> N.asarray([[0,1],[2,3]]) == N.asarray([[1,1],[3,3],[5,5]])
False


On Oct 11, 2010, at 8:58 PM, Vincent Davis wrote:

> Not sure about "be broadcasted to the same shape"
> I would kind of expect == to return true, false or some error.



More information about the NumPy-Discussion mailing list