[Numpy-discussion] astype
Brennan Williams
brennan.williams at visualreservoir.com
Sat Feb 14 17:30:24 EST 2009
Nils Wagner wrote:
> On Sat, 14 Feb 2009 17:22:43 +0100
> "Nils Wagner" <nwagner at 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 at scipy.org
>> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> Sorry for the noise - dots and commas were mixed up in
> the input file.
>
>
Mind you, it raises an interesting point. What if the string was an
amount in currency, e.g. '$1,000.00' or perhaps just '1,000.00' etc.
How would one convert a string array in that format to a float array?
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
More information about the NumPy-Discussion
mailing list