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, addition, etc. Here is a demonstration, observed with svn 6456:
import numpy as np class MyArray(np.ndarray): __array_priority__ = 20 def __new__(cls): return np.asarray(1).view(cls).copy() def __array_wrap__(self, obj, context=None): print 'array wrap:', self, obj, context return obj.view(type(self)) def __str__(self): return 'MyArray(%s)'%super(MyArray,self).__str__() mine = MyArray() print 3*mine print mine*3 print [1,2,3]*mine print mine*[1,2,3] print print 3/mine print mine/3 print [1,2,3]*mine print mine*[1,2,3] print print 3+mine print mine+3 print [1,2,3]+mine print mine+[1,2,3] print print 3/mine print mine/3 print [1,2,3]/mine print mine/[1,2,3] print print 3**mine print mine**3 print [1,2,3]**mine print mine**[1,2,3]
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion