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

NumPy Trac numpy-tickets@scipy....
Tue Sep 14 07:33:58 CDT 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  |  
----------------------------------+-----------------------------------------
 There is an issue when using astype() on a scalar array,
 i.e. with shape == (), when doing an endiannes change
 (possible in other cases too?)

 Example:

 >>> import numpy as np
 >>>
 >>> np.array(42).astype(">i4").dtype
 dtype('>i4')
 >>> np.array(42, dtype=">i4").astype('>i4').dtype
 dtype('int32')
 >>> np.array([42]).astype(">i4").dtype
 dtype('>i4')
 >>> np.array([42], dtype=">i4").astype('>i4').dtype
 dtype('>i4')

 Above one should get dtype('>i4') in both cases.


 >>> np.array(42, dtype=">f4").astype('>f4').dtype
 dtype('float32')
 >>> np.array([42], dtype=">f4").astype('>f4').dtype
 dtype('>f4')

 And here dtype('>f4') in both cases.


 >>> np.array(42, dtype=">f8").astype('>f8').dtype
 dtype('float64')
 >>> np.array([42], dtype=">f8").astype('>f8').dtype
 dtype('>f8')

 And here dtype('>f8') in both cases.


 My numpy version
 >>> np.version.version
 '1.4.0.dev7417'

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


More information about the NumPy-Tickets mailing list