[Numpy-discussion] possible bug: __array_wrap__ is not called during arithmetic operations in some cases

Stéfan van der Walt stefan@sun.ac...
Sun Feb 22 17:28:20 CST 2009

2009/2/23 Eric Firing <efiring@hawaii.edu>:
> Darren Dale wrote:
>> Does anyone know why __array_wrap__ is not called for subclasses during
>> arithmetic operations where an iterable like a list or tuple appears to
>> the right of the subclass? When I do "mine*[1,2,3]", array_wrap is not
>> called and I get an ndarray instead of a MyArray. "[1,2,3]*mine" is
>> fine, as is "mine*array([1,2,3])". I see the same issue with division,
> The masked array subclass does not show this behavior:

Maybe because it defines __mul__.  If I change Darren's class to include

    def __mul__(self, y):
        return y * self

It works as expected.


More information about the Numpy-discussion mailing list