I think the easiest is to use an intermediate string. If your file is test.txt,
In [22]: a = file('test.txt').read().replace(',','.')
In [23]: import StringIO
In [24]: b=genfromtxt(StringIO.StringIO(a))
In [25]: b
Out[25]:
array([[ 0.00000000e+00, 1.22100000e-03, 1.22100000e-03,
0.00000000e+00, 1.27807600e+00, 1.60102539e+02],
[ 4.00000000e-07, 0.00000000e+00, 0.00000000e+00,
2.44100000e-03, 1.27929700e+00, 1.60000000e+02],
[ 8.00000000e-07, -1.22100000e-03, 0.00000000e+00,
1.22100000e-03, 1.27929700e+00, 1.59897461e+02],
[ 1.20000000e-06, 0.00000000e+00, 0.00000000e+00,
1.22100000e-03, 1.27929700e+00, 1.60000000e+02],
[ 1.60000000e-06, -1.22100000e-03, 0.00000000e+00,
3.66200000e-03, 1.27807600e+00, 1.59897461e+02],
[ 2.00000000e-06, 0.00000000e+00, -1.22100000e-03,
3.66200000e-03, 1.27929700e+00, 1.60000000e+02]])
On Fri, Jun 3, 2011 at 11:30 PM, jgrub <[email protected]> wrote:
>
> Hello, im actually try to read in data with genfromtxt(),
> i want to read in numbers which are stored in a textfile like this:
>
> 0,000000 0,001221 0,001221 0,000000 1,278076
> 160,102539
>
> 4,000000E-7 0,000000 0,000000 0,002441 1,279297
> 160,000000
>
> 8,000000E-7 -0,001221 0,000000 0,001221 1,279297
> 159,897461
>
> 1,200000E-6 0,000000 0,000000 0,001221 1,279297
> 160,000000
>
> 1,600000E-6 -0,001221 0,000000 0,003662 1,278076
> 159,897461
>
> 2,000000E-6 0,000000 -0,001221 0,003662 1,279297
> 160,000000
>
> my problem is that they are seperated with a comma so when i try to read
> them
> i just get a numpy array with NaN's. is there a short way to replace the
> "," with "." ?
>
> --
> View this message in context:
> http://old.nabble.com/numpy-input-with-genfromttxt%28%29-tp31757790p31757790.html
> Sent from the Numpy-discussion mailing list archive at Nabble.com.
>
> _______________________________________________
> NumPy-Discussion mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion