[Numpy-discussion] dtyping with .astype()

Alex van der Spek zdoor at xs4all.nl
Thu Oct 13 06:59:02 EDT 2011


Beginner's question?

I have this dictionary dtypes of names and types:

>>>dtypes
{'names': ['col1', 'col2', 'col3', 'col4', 'col5'], 'formats': [<type 
'numpy.float16'>, <type 'numpy.float16'>, <type 'numpy.float16'>, <type 
'numpy.float16'>, <type 'numpy.float16'>]}

and this array y

>>> y
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34],
       [35, 36, 37, 38, 39],
       [40, 41, 42, 43, 44],
       [45, 46, 47, 48, 49]])


But:
>>>>z=y.astype(dtypes)

gives me a confusing result. I only asked to name the columns and change their 
types to half precision floats.

What am I missing? How to do this?

Thank you in advance, 
Alex van der Spek




More information about the NumPy-Discussion mailing list