[NumPy-Tickets] [NumPy] #1611: Different behaviour in ndarray.astype() for scalars and arrays

NumPy Trac numpy-tickets@scipy....
Mon Nov 15 20:52:03 CST 2010


#1611: Different behaviour in ndarray.astype() for scalars and arrays
----------------------------------+-----------------------------------------
 Reporter:  lorenz                |       Owner:  somebody   
     Type:  defect                |      Status:  new        
 Priority:  normal                |   Milestone:  Unscheduled
Component:  numpy.core            |     Version:  1.4.0      
 Keywords:  astype, dtype, shape  |  
----------------------------------+-----------------------------------------
Changes (by lamblin):

 * cc: blip@… (added)


Comment:

 Possibly related, another weird behaviour of astype() on scalar arrays:

 >>> a = numpy.asarray(0, dtype='int16')
 >>> type(a)
 <type 'numpy.ndarray'>

 If I convert it to a different type, I get another ndarray:
 >>> type(a.astype('int8'))
 <type 'numpy.ndarray'>

 However, if I convert it to the same type ('int16'), I get a numpy scalar
 instead:
 >>> type(a.astype('int16'))
 <type 'numpy.int16'>

 Two calls to 'astype' with the same type always seem to do that:
 >>> type(a.astype('float64').astype('float64'))
 <type 'numpy.float64'>

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


More information about the NumPy-Tickets mailing list