[Numpy-discussion] astype

Nils Wagner nwagner@iam.uni-stuttgart...
Sat Feb 14 10:27:28 CST 2009


On Sat, 14 Feb 2009 17:22:43 +0100
  "Nils Wagner" <nwagner@iam.uni-stuttgart.de> wrote:
> 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
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion


Sorry for the noise -  dots and commas were mixed up in 
the input file.

  


More information about the Numpy-discussion mailing list