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

Stef Mientki stef.mientki@gmail....
Tue Feb 26 15:51:39 CST 2008


hello,
thank you all for your suggestions,
but unfortunately I couldn't get one working.
Also the Cookbook is much more complicated (for me) than the orginal 
"double asarray",
maybe the CR/LF is causing the trouble.
As the datasets are not that big it's not a real issue.

Sebastian Haase wrote:
> 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 )
>>
>>     
>
> do really mean a "full blown crash", i.e. seg-fault ??
>
>   

No I mean traceable crashes, here are few on the suggestions made by others:
  data_all = loadtxt(filename)
  x,y,z = loadtxt ( filename, unpack=True )
  """
  Traceback (most recent call last):
    File "D:\data_to_test\signal_workbench.py", line 594, in ?
      Read_New_Akto_File ( filename, True)
    File "D:\data_to_test\signal_workbench.py", line 563, in 
Read_New_Akto_File
      data_all = loadtxt(filename)
    File 
"P:\Python\lib\site-packages\numpy-1.0.3.dev3722-py2.4-win32.egg\numpy\core\numeric.py", 
line 725, in loadtxt
      X = array(X, dtype)
  ValueError: setting an array element with a sequence.
  """
 
  x,y,z = load(filename)
  """
  Traceback (most recent call last):
    File "D:\data_to_test\signal_workbench.py", line 659, in ?
      Read_New_Akto_File ( filename, True)
    File "D:\data_to_test\signal_workbench.py", line 628, in 
Read_New_Akto_File
      x,y,z = load(filename)
    File 
"P:\Python\lib\site-packages\numpy-1.0.3.dev3722-py2.4-win32.egg\numpy\core\numeric.py", 
line 611, in load
      return _cload(file)
  UnpicklingError: unpickling stack underflow
  """
 
  data_all = loadtxt ( filename, usecols=(0,1,2) )
  """
  Traceback (most recent call last):
    File "D:\data_to_test\signal_workbench.py", line 673, in ?
      Read_New_Akto_File ( filename, True)
    File "D:\data_to_test\signal_workbench.py", line 640, in 
Read_New_Akto_File
      data_all = loadtxt ( filename, usecols=(0,1,2) )
    File 
"P:\Python\lib\site-packages\numpy-1.0.3.dev3722-py2.4-win32.egg\numpy\core\numeric.py", 
line 718, in loadtxt
      row = [converterseq[j](vals[j]) for j in usecols]
  IndexError: list index out of range
  """

cheers,
Stef

> -Sebastian Haase
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>   



More information about the SciPy-user mailing list