Operating environment
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
GNU bash, version 4.3.8(1)-release (x86_64-pc-linux-gnu)
I want to read the value of a file like the following.
$ head IntField-Y
x y z |E|^2 Ex.r Ex.i Ey.r Ey.i Ez.r Ez.i
-0.2094395102 -1.466076572 -5.235987756 1.117036835 -0.02405501404 0.01851210121 0.4265089085 0.9619413614 0.0789243352 -0.05143356113
0.2094395102 -1.466076572 -5.235987756 1.117036835 0.02405501406 -0.01851210123 0.4265089085 0.9619413614 0.0789243352 -0.05143356113
-1.047197551 -1.047197551 -5.235987756 1.080829273 -0.03701212691 0.09467516163 0.4467058558 0.9303997369 0.0629824475 -0.0365979255
-0.6283185307 -1.047197551 -5.235987756 0.8888575386 -0.01687903824 -0.0712841231 0.4031262231 0.8443906708 0.08152662539 -0.0365822794
-0.2094395102 -1.047197551 -5.235987756 1.355786123 0.000532696637 -0.07408332312 0.2568592009 1.131470229 0.05970715325 -0.02304404718
0.2094395102 -1.047197551 -5.235987756 1.355786123 -0.0005326966253 0.0740833231 0.256859201 1.131470229 0.05970715325 -0.02304404718
0.6283185307 -1.047197551 -5.235987756 0.8888575386 0.01687903825 0.07128412309 0.4031262231 0.8443906708 0.08152662538 -0.0365822794
1.047197551 -1.047197551 -5.235987756 1.080829273 0.03701212691 -0.09467516164 0.4467058558 0.9303997368 0.06298244747 -0.03659792549
-1.047197551 -0.6283185307 -5.235987756 1.699276704 -0.02108930862 -0.06464253993 0.3399972729 1.255779421 0.04140882396 -0.01893399186
The delimiter is a space, not a comma.
http://www.mwsoft.jp/programming/numpy/csv.html
test_read_170418a.py
import numpy as np
data = np.loadtxt('IntField-Y', delimiter=' ')
print(data[:,0]) # 1st columne
print(data[:,1]) # 2nd columne
run
$ python test_read_170418a.py
Traceback (most recent call last):
File "test_read_170418a.py", line 9, in <module>
data = np.loadtxt('IntField-Y', delimiter=' ')
File "/home/user/tensorflow-GPU/local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 930, in loadtxt
items = [conv(val) for (conv, val) in zip(converters, vals)]
File "/home/user/tensorflow-GPU/local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 659, in floatconv
return float(x)
ValueError: could not convert string to float: x
[1]+End subl test_read_170418a.py
Item name line(x y z |E|^2 Ex.r Ex.i Ey.r Ey.i Ez.r Ez.i
)I get an error.
test_read_170419a.py
import numpy as np
#data = np.loadtxt('IntField-Y', delimiter=' ')
data = np.genfromtxt('IntField-Y', delimiter=' ')
print(data[:,0]) # 1st columne
print(data[:,1]) # 2nd columne
run
$ python test_read_170419a.py
[ nan -0.20943951 0.20943951 ..., 1.04719755 -0.20943951
0.20943951]
[ nan -1.46607657 -1.46607657 ..., 1.04719755 1.46607657
1.46607657]
I was able to read a space-separated data file with a line of item names by using genfromtxt (). The character string in the line of the item name is nan, but there is no problem because it is not treated as data.
Recommended Posts