[NumPy-Tickets] [NumPy] #1186: numpy.ma.abs not working correctly?

NumPy Trac numpy-tickets@scipy....
Mon Apr 5 13:03:39 CDT 2010


#1186: numpy.ma.abs not working correctly?
-------------------------+--------------------------------------------------
  Reporter:  dalloliogm  |       Owner:  pierregm
      Type:  defect      |      Status:  closed  
  Priority:  normal      |   Milestone:          
 Component:  Other       |     Version:  1.3.0   
Resolution:  invalid     |    Keywords:          
-------------------------+--------------------------------------------------
Changes (by pierregm):

  * status:  new => closed
  * resolution:  => invalid


Comment:

 The more I think about it, the less I can think about a generic solution.
 The issue is that your ma1 array has a np.object dtype (because of the
 presence of None in your initial dataset). Masking the None entries
 doesn't change anything: your masked array still has a np.object dtype.
 np.abs or ma.abs don't know how to process object arrays. You need to find
 a way to force your array to another dtype, such as for example
 {{{
 ma.array(ma1.filled(0), mask=ma1.mask, dtype=int)
 }}}
 Here, the entries that were initially None are replaced by 0
 ({{{ma1.filled(0)}}}), but you keep the mask and force the dtype to int.
 Now you have an integer array on which you call np.abs or ma.abs...

 A generic solution would require to guess the dtype to expect. I don't
 think this is advisable, the user should decide for him/herself. There's
 nothing else we can do, so I'm closing the ticket.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1186#comment:3>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list