[Tutor] reading a string into an array

Bryan Fodness bryan.fodness at gmail.com
Sat May 31 21:43:17 CEST 2008


I am trying to read a long string of values separated by a backslash into an
array of known size.

Here is my attempt,

from numpy import *
ay, ax = 384, 512
a = zeros([ay, ax])
for line in open('out.out'):
    data = line.split('\\')
k = 0
for i in range(ay):
    for j in range(ax):
        a[i, j] = data[k]
        k+=1
but, I receive the following error.

Traceback (most recent call last):
  File "C:/Users/bryan/Desktop/dose_array.py", line 13, in <module>
    a[i, j] = data[k]
ValueError: setting an array element with a sequence.




-- 
"The game of science can accurately be described as a never-ending insult to
human intelligence." - João Magueijo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080531/b70501ba/attachment.htm>


More information about the Tutor mailing list