[Numpy-tickets] [NumPy] #1026: ufuncs do not respect ndarray subclasses in some cases

NumPy numpy-tickets@scipy....
Wed Feb 25 05:56:49 CST 2009


#1026: ufuncs do not respect ndarray subclasses in some cases
------------------------+---------------------------------------------------
 Reporter:  DarrenDale  |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  high        |   Milestone:  1.3.0   
Component:  numpy.core  |     Version:  none    
 Severity:  major       |    Keywords:          
------------------------+---------------------------------------------------
 The following script demonstrates that ufuncs do not respect ndarray
 subclasses when an iterable like list or tuple is passed to the second
 argument. I have also seen this behavior with numpy's !MaskedArray.

 {{{
 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 np.multiply(3,mine) # yields MyArray
 print np.multiply(mine,3) # yields MyArray
 print np.multiply([1,2,3],mine) # yields MyArray
 print np.multiply(mine,[1,2,3]) # yields ndarray
 print np.multiply(mine,(1,2,3)) # yields ndarray
 print np.multiply(mine,np.array([1,2,3])) # yields MyArray
 }}}

-- 
Ticket URL: <http://scipy.org/scipy/numpy/ticket/1026>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list