[SciPy-user] Convert a string list to array ?
Travis E. Oliphant
Tue Feb 26 16:46:18 CST 2008
Stef Mientki wrote:
> I have a string list that I want to convert to an integer array
> data_all = [ '12', '24' ]
> and now I would expect this would work, but it crashes:
> data_all = asarray ( data_all, dtype = int )
Yeah, perhaps unexpectedly, the conversion code requires integers not
strings when you specify dtype=int.
You can also do:
asarray([int(x) for x in data_all],dtype=int)
More information about the SciPy-user