Converting an array of string to array of float
Rafael Durán Castañeda
rafadurancastaneda at gmail.com
Fri Mar 25 11:46:47 EDT 2011
But you must be sure that the list only contains objects than can be
converted into float, if not you'll get:
>>> float('something')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
float('something')
ValueError: could not convert string to float: something
>>>
2011/3/25 Blockheads Oi Oi <breamoreboy at yahoo.co.uk>
> On 25/03/2011 15:27, Jason Swails wrote:
>
>> I'm guessing you have something like
>>
>> list1=['1.0', '2.3', '4.4', '5.5', ...], right?
>>
>> You can do this:
>>
>> for i in range(len(list1)):
>> list1[i] = float(list1[i])
>>
>>
> or
>
> for i, x in enumerate(list1):
> list1[i] = float(x)
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110325/92d9798c/attachment.html>
More information about the Python-list
mailing list