[Numpy-discussion] Allow == and != to raise errors

Nathaniel Smith njs at pobox.com
Mon Jul 15 10:20:13 EDT 2013


On Mon, Jul 15, 2013 at 2:09 PM, bruno Piguet <bruno.piguet at gmail.com> wrote:
> Python itself doesn't raise an exception in such cases :
>
>>>> (3,4) != (2, 3, 4)
> True
>>>> (3,4) == (2, 3, 4)
> False
>
> Should numpy behave differently ?

The numpy equivalent to Python's scalar "==" is called array_equal,
and that does indeed behave the same:

In [5]: np.array_equal([3, 4], [2, 3, 4])
Out[5]: False

But in numpy, the name "==" is shorthand for the ufunc np.equal, which
raises an error:

In [8]: np.equal([3, 4], [2, 3, 4])
ValueError: operands could not be broadcast together with shapes (2) (3)

-n



More information about the NumPy-Discussion mailing list