[Numpy-discussion] should numpy.equal raise an exception instead of returning NotImplemented?
Ernest Adrogué
eadrogue at gmx.net
Tue Jan 26 08:28:15 EST 2010
Hi,
Do you think it is sensible for np.equal to return a NotImplemented
object when is given an array of variable length dtype?
Consider this code:
x = np.array(['xyz','zyx'])
np.where(np.equal(x, 'zyx'), [0,0], [1,1])
the last line returns array([0, 0]) which is wrong. Compare with
np.where(x == 'zyx', [0,0], [1,1])
I think in this case raising an exception would be better, because
of the way np.equal is often used as an argument to another function.
It's not easy to see where the bug is or even that there is a bug
in your code.
Cheers.
Ernest
More information about the NumPy-Discussion
mailing list