Thank-you for your explanations. So, if the operator "==" applied to np.arrays is a shorthand for the ufunc np.equal, it should definitly behave exactly as np.equal(), and raise an error.
One side question about style : In case you would like to protect a "x == y" test by a try/except clause, wouldn't it feel more "natural" to write " np.equal(x, y)" ? Bruno. 2013/7/15 Nathaniel Smith <[email protected]> > On Mon, Jul 15, 2013 at 2:09 PM, bruno Piguet <[email protected]> > 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 > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion >
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
