ADDA > convertToInputcsv_170422.py > TensorFlow用のファイル(input.csv)に変換 > v0.1

```txt:動作環境
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)
```

This article is related to [ADDA (light scattering simulator based on the discrete dipole approximation)](https://github.com/adda-team/adda/).


### InitField-Y

```bash
$ 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 0.4481601286 0.1631827602 0.1136883225 0.5191361677 0.3564084944 -0.1097504118 0.005652637511
0.2094395102 -1.466076572 -5.235987756 0.7745881872 0.1098627477 0.07526815655 0.8067658221 0.3136058991 -0.08733927173 0.002273400976
-1.047197551 -1.047197551 -5.235987756 0.11714951 0.01143212548 0.1054770412 -0.1519192093 0.2845811388 -0.04028466164 0.01430683806
-0.6283185307 -1.047197551 -5.235987756 0.1951690014 0.1179491742 0.09099830363 0.1326218142 0.3899160502 -0.04912997581 0.03065087379
-0.2094395102 -1.047197551 -5.235987756 0.3872950636 0.1719851184 0.04449915171 0.4226400539 0.4162386629 -0.05432106683 0.03009967244
0.2094395102 -1.047197551 -5.235987756 0.5623337432 0.1345745413 0.08159228707 0.6960987616 0.2283745441 -0.02927571502 0.0008055442539
0.6283185307 -1.047197551 -5.235987756 0.6510356113 0.101646831 -0.02684327634 0.7978570253 0.04091821028 -0.02392884861 -0.03406242954
1.047197551 -1.047197551 -5.235987756 0.5485766074 0.04689584344 -0.05569883516 0.7281592273 -0.100947639 -0.03418497024 -0.04123261679
-1.047197551 -0.6283185307 -5.235987756 0.150497933 0.01971488155 0.08314960573 -0.2755689582 0.2560853162 -0.04039547019 0.006757636442
```

- 空白区切りをカンマ区切りにする
- TensorFlowの学習に用いる項目だけにする

上記のための変換コードを作った。

### code v0.1

```convertToInputcsv_170422.py
import numpy as np

'''
v0.1 Apr. 22, 2017
   - read 'IntField' then output for TensorFlow
'''

#codingrule: PEP8

data = np.genfromtxt('IntField-Y', delimiter=' ')
#print(data[1:, 0])  # 1st columne
#print(data[1:, 1])  # 2nd columne

xpos, ypos, zpos = data[1:, 0], data[1:, 1], data[1:, 2]
E2 = data[1:, 3]
Exr, Exi = data[1:, 4], data[1:, 5]
Eyr, Eyi = data[1:, 6], data[1:, 7]
Ezr, Ezi = data[1:, 8], data[1:, 9]

list = zip(xpos, ypos, zpos, Exr, Exi, Eyr, Eyi, Ezr, Ezi)

for tpl in list:
    print("%s, %s, %s, %s, %s, %s, %s, %s, %s" % tpl)

```

```txt:run
$ python convertToInputcsv_170422.py > input.csv 
```

```bash
$ head input.csv 
-0.2094395102, -1.466076572, -5.235987756, 0.1631827602, 0.1136883225, 0.5191361677, 0.3564084944, -0.1097504118, 0.005652637511
0.2094395102, -1.466076572, -5.235987756, 0.1098627477, 0.07526815655, 0.8067658221, 0.3136058991, -0.08733927173, 0.002273400976
-1.047197551, -1.047197551, -5.235987756, 0.01143212548, 0.1054770412, -0.1519192093, 0.2845811388, -0.04028466164, 0.01430683806
-0.6283185307, -1.047197551, -5.235987756, 0.1179491742, 0.09099830363, 0.1326218142, 0.3899160502, -0.04912997581, 0.03065087379
-0.2094395102, -1.047197551, -5.235987756, 0.1719851184, 0.04449915171, 0.4226400539, 0.4162386629, -0.05432106683, 0.03009967244
0.2094395102, -1.047197551, -5.235987756, 0.1345745413, 0.08159228707, 0.6960987616, 0.2283745441, -0.02927571502, 0.0008055442539
0.6283185307, -1.047197551, -5.235987756, 0.101646831, -0.02684327634, 0.7978570253, 0.04091821028, -0.02392884861, -0.03406242954
1.047197551, -1.047197551, -5.235987756, 0.04689584344, -0.05569883516, 0.7281592273, -0.100947639, -0.03418497024, -0.04123261679
-1.047197551, -0.6283185307, -5.235987756, 0.01971488155, 0.08314960573, -0.2755689582, 0.2560853162, -0.04039547019, 0.006757636442
-0.6283185307, -0.6283185307, -5.235987756, 0.06619290684, 0.04183265213, 0.08778209189, 0.3944779431, -0.03724331442, 0.02027978893
```