[SciPy-user] Convert a string list to array ?

Emanuele Zattin emanuelez@gmail....
Tue Feb 26 14:07:18 CST 2008


Hi,

I think there's something about it in the cookbook:

http://www.scipy.org/Cookbook/InputOutput

On Tue, Feb 26, 2008 at 8:50 PM, Stef Mientki <s.mientki@ru.nl> wrote:
> hello,
>
>  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 )
>
>  so I need to do the conversion in 2 steps
>   data_all = asarray ( asarray ( data_all ), dtype = int )
>
>  Is there a better (more elegant) way ?
>
>
>  And maybe the string list was even the wrong first step,
>  the datafile I'm reading looks like this:
>
>  254 48 57
>  58 52 53
>  58 51 54
>  254 32 32
>  32 32 32
>
>  So there might even be better ways to start ?
>
>
>  thanks,
>  Stef
>  _______________________________________________
>  SciPy-user mailing list
>  SciPy-user@scipy.org
>  http://projects.scipy.org/mailman/listinfo/scipy-user
>



-- 
Emanuele Zattin
---------------------------------------------------
-I don't have to know an answer. I don't feel frightened by not
knowing things; by being lost in a mysterious universe without any
purpose — which is the way it really is, as far as I can tell,
possibly. It doesn't frighten me.- Richard Feynman


More information about the SciPy-user mailing list