[Numpy-discussion] Equality not working as expected with ndarray sub-class
Thomas Robitaille
thomas.robitaille at gmail.com
Thu Jul 4 09:06:49 EDT 2013
Hi everyone,
The following example:
import numpy as np
class SimpleArray(np.ndarray):
__array_priority__ = 10000
def __new__(cls, input_array, info=None):
return np.asarray(input_array).view(cls)
def __eq__(self, other):
return False
a = SimpleArray(10)
print (np.int64(10) == a)
print (a == np.int64(10))
gives the following output
$ python2.7 eq.py
True
False
so that in the first case, SimpleArray.__eq__ is not called. Is this a
bug, and if so, can anyone think of a workaround? If this is expected
behavior, how do I ensure SimpleArray.__eq__ gets called in both
cases?
Thanks,
Tom
ps: cross-posting to stackoverflow
More information about the NumPy-Discussion
mailing list