[NumPy-Tickets] [NumPy] #2156: array_split does not preserve dtype of original array when subarray length is 0.

NumPy Trac numpy-tickets@scipy....
Mon Jun 11 20:22:14 CDT 2012


#2156: array_split does not preserve dtype of original array when subarray length
is 0.
-------------------------+--------------------------------------------------
 Reporter:  rainwoodman  |       Owner:  somebody   
     Type:  defect       |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  Other        |     Version:  1.6.1      
 Keywords:               |  
-------------------------+--------------------------------------------------
 The original dtype is u4, but the output becomes f8.

 {{{
 In [4]: numpy.array_split ( zeros(shape=4, dtype='u4'), 10)
 Out[4]:
 [array([0], dtype=uint32),
  array([0], dtype=uint32),
  array([0], dtype=uint32),
  array([0], dtype=uint32),
  array([], dtype=float64),
  array([], dtype=float64),
  array([], dtype=float64),
  array([], dtype=float64),
  array([], dtype=float64),
  array([], dtype=float64)]


 }}}

 The following code seems to be causing the problem:
 {{{

 def _replace_zero_by_x_arrays(sub_arys):
     for i in range(len(sub_arys)):
         if len(_nx.shape(sub_arys[i])) == 0:
             sub_arys[i] = _nx.array([])
         elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)):
             sub_arys[i] = _nx.array([])
     return sub_arys
 }}}

 shouldn't those _nx.array([]) be replaced by _nx.array([],
 dtype=sub_arys[i].dtype)?

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


More information about the NumPy-Tickets mailing list