[NumPy-Tickets] [NumPy] #1560: atleast_3d() strips subclass info

NumPy Trac numpy-tickets@scipy....
Tue Jul 27 10:24:32 CDT 2010


#1560: atleast_3d() strips subclass info
------------------------+---------------------------------------------------
 Reporter:  weathergod  |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  high        |   Milestone:  1.5.0   
Component:  Other       |     Version:          
 Keywords:              |  
------------------------+---------------------------------------------------
 The .atleast_3d() function can not be used with arrays that are subclassed
 from ndarray().  Because the function uses .asarray() instead of
 .asanyarray(), subclass info such as masks for masked arrays are stripped
 from the results.  See the following example:
 {{{
 >>> a = numpy.ma.masked_array([0.0, 1.2, 3.5], mask=[False, True, False])
 >>> b = numpy.atleast_3d(a)
 >>> b
 array([[[ 0. ],
         [ 1.2],
         [ 3.5]]])
 >>> a
 masked_array(data = [0.0 -- 3.5],
              mask = [False  True False],
        fill_value = 1e+20)

 >>>
 }}}

 Note that the .atleast_1d() and .atleast_2d() functions are safe for
 subclassed arrays.  I believe that simply replacing .asarray() with
 .asanyarray() should fix the issue.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1560>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list