I have a question about reading array from file.
I wrote some array at file like below.
file name: xy0.dat
[2, 4, 6]
[4, 8, 12]
...
...
Now, I want to read this array(not string) at my original file.
I want to define x0[0] = [2,4,6] and
x0[1] = [4,8,12]
...
-------------------------code---------------------------------------------------
from numpy import*
from scipy import*
import array
x0 = zeros(10000)
inFile = open('xy0.dat', 'r')
x0=[]
for line in inFile.readlines():
line.split()
x0.append(line)
print x0[0]
---------------------------result-----------------------------------------------------------------
[2, 4, 6]
----------------------------Question------------------------------------------------------------------------
okay. but it looks like string, not array.
because if I change the last part like below, there is some error message.
------------------------------Question code----------------------------------------------------------------
from numpy import*
from scipy import*
import array
x0 = zeros(10000)
inFile = open('xy0.dat', 'r')
x0=[]
for line in inFile.readlines():
line.split()
x0.append(line)
a = x0[0]
print sum(a)
---------------------Question result------------------------------------
Traceback (most recent call last):
File "ex4.py", line 15, in <module>
print sum(a)
File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line 633, in sum
return _wrapit(x, 'sum', axis, dtype, out)
File "/usr/lib/python2.5/site-packages/numpy/core/fromnumeric.py", line 37, in _wrapit
result = getattr(asarray(obj),method)(*args, **kwds)
TypeError: cannot perform reduce with flexible type
please help me....
Editor's note:
Please use the [code=python] and [/code] tag pair to enclose your python code.