[Numpy-discussion] astype

Nils Wagner nwagner@iam.uni-stuttgart...
Sat Feb 14 10:22:43 CST 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