[Numpy-tickets] [NumPy] #744: Loss of dimension bug in numpy.ma.__getitem__ for arrays of shape (n, 1) or (1, n) or (n, 1, 1, ...)

NumPy numpy-tickets@scipy....
Sat Apr 19 00:57:47 CDT 2008


#744: Loss of dimension bug in numpy.ma.__getitem__ for arrays of shape (n, 1) or
(1, n) or (n, 1, 1, ...)
----------------------+-----------------------------------------------------
 Reporter:  dharland  |       Owner:  somebody
     Type:  defect    |      Status:  new     
 Priority:  normal    |   Milestone:  1.0.5   
Component:  Other     |     Version:  none    
 Severity:  normal    |    Keywords:          
----------------------+-----------------------------------------------------
 There is a bug in MaskedArray.__getitem__ that causes a loss in dimension
 for masked arrays of shape (n, 1) or (1, n) or more generally, any shape
 of the form (1,)*a + (n,) + (1,)*b

 Heres an example

 {{{
   # A 2d column vector
   x = ma.arange(5).reshape( (-1, 1) )

   # mask a point
   x[3] = ma.masked

   # Different behavior for unmasked and masked items
   print x[0], x[0].shape
   print x[3], x[3].shape
 }}}

 this produces as output

 {{{
   [0] (1,)    # Correct
   -- ()       # This should be [--]
 }}}

 As a result code cannot reliably iterate over rows of a 2d array (in case
 its in fact a (n,1) array)

 The error appears in the following code snippet in numpy/core/ma.py:
 {{{
         mi = m[i]
         if mi.size == 1:    # <-- Should this be if mi.size == 1 and
 mi.ndim == 0
             if mi:
                 return masked    # <-- dimension loss here if mi.ndim > 0
             else:
                 return dout
 }}}

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


More information about the Numpy-tickets mailing list