[Numpy-discussion] Allow == and != to raise errors
nouiz at nouiz.org
Mon Jul 15 10:57:17 EDT 2013
Just a question, should == behave like a ufunc or like python == for tuple?
I think that all ndarray comparision (==, !=, <=, ...) should behave the
same. If they don't (like it was said), making them consistent is good.
What is the minimal change to have them behave the same? From my
understanding, it is your proposal to change == and != to behave like real
ufunc. But I'm not sure if the minimal change is the best, for new user,
what they will expect more? The ufunc of the python behavior?
Anyway, I see the advantage to simplify the interface to something more
Anyway, if we make all comparison behave like ufunc, there is array_equal
as said to have the python behavior of ==, is it useful to have equivalent
function the other comparison? Do they already exist.
On Mon, Jul 15, 2013 at 10:20 AM, Nathaniel Smith <njs at pobox.com> wrote:
> On Mon, Jul 15, 2013 at 2:09 PM, bruno Piguet <bruno.piguet at gmail.com>
> > 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 : np.array_equal([3, 4], [2, 3, 4])
> Out: False
> But in numpy, the name "==" is shorthand for the ufunc np.equal, which
> raises an error:
> In : np.equal([3, 4], [2, 3, 4])
> ValueError: operands could not be broadcast together with shapes (2) (3)
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion