should numpy.equal raise an exception instead of returning NotImplemented?
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
2010/1/26 Ernest Adrogué <eadrogue@gmx.net>:
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.
there was a thread on this on december 7, but maybe nobody filed a ticket. Josef
Cheers.
Ernest _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
26/01/10 @ 08:59 (-0500), thus spake josef.pktd@gmail.com:
2010/1/26 Ernest Adrogué <eadrogue@gmx.net>:
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.
there was a thread on this on december 7, but maybe nobody filed a ticket.
This ticket http://projects.scipy.org/numpy/changeset/7878 seems to imply that now ufuncs raise an exception, so maybe it's already been taken care of. Thanks. Ernest
participants (2)
-
Ernest Adrogué -
josef.pktd@gmail.com