[Numpy-discussion] Difference in astype() for scalars and arrays?

Lorenz Hüdepohl lorenz@MPA-Garching.MPG...
Mon Sep 13 06:51:51 CDT 2010


Hi All,

I'm fiddling with some endianness / binary representation issue and stumbled 
upon this puzzling behavior of astype(): It does not seem to work as 
expected - for me at least ;) - when given a scalar:

>>> 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')


Shouldn't I always get dtype('>i4')?

Regards,
	Lorenz

PS:
>>> np.version.version
'1.4.0.dev7417'


More information about the NumPy-Discussion mailing list