[Numpy-discussion] astype

Nils Wagner nwagner at iam.uni-stuttgart.de
Sat Feb 14 11:22:43 EST 2009


Hi all,

How can I convert an array with string elements to
an array with float entries ?


  
>>> coord_info[:,1]
array(['0,0', '100,0', '200,0', '300,0', '400,0', '500,0', 
'600,0', '700,0', '800,0', '0.0', '100.0', '200.0', 
'300.0', '400.0', '500.0', '600.0',
        '700.0', '800.0', '0.0', '100.0', '200.0', 
'300.0', '400.0', '500.0', '600.0', '700.0', '800.0', 
'0.0', '100.0', '200.0', '300.0', '400.0',
        '500.0', '600.0', '700.0', '800.0', '0.0', 
'100.0', '200.0', '300.0', '400.0', '500.0', '600.0', 
'700.0', '800.0'],
       dtype='|S50')

>>> coord_info[:,1].astype(float)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): 0,0


Nils



More information about the NumPy-Discussion mailing list