TensorFlow / ADDA > 線形方程式の初期値用データの学習 > 結果確認コード:v0.2, v0.3

```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)
```

v0.1: http://qiita.com/7of9/items/09262a2ab01d037d169b

結果確認コードを変更して、Y, Z方向の電場Eの実部、虚部の値を扱えるようにした。
その中で学んだことが、Enumに相当するものの実装。

https://docs.python.jp/3/library/enum.html

### code v0.2

targetIdxの指定`TARGET_IDX.EXR`を`TARGET_IDX.EZI`などのように変更することで、Y, Zの電場の実部、虚部を切り替えることが可能。

Jupyter code

**実行にはv0.1で作成したLN-INPUT-CSVが必要。**

```py:check_resultmap_170429.ipynb
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import math
import sys
import matplotlib.pyplot as plt
import matplotlib.cm as cm

'''
v0.2 Mar. 03, 2017
   - add [Elist] instead of each of [Exr, Exi, ...]
   - add [targetIdx] for selection of the target item
   - add enum [TARGET_IDX]
v0.1 Apr. 29, 2017
   - use snippet from [check_resultmap_170329.ipynb] v0.2
'''
# codingrule:PEP8

src_data = np.genfromtxt('LN-INPUT-CSV', delimiter=',')

xpos, ypos, zpos = src_data[:, 0], src_data[:, 1], src_data[:, 2]
# Exr, Exi, Eyr, Eyi, Ezr, Ezi
Elist = [src_data[:, idx] for idx in range(3, 9)]


class TARGET_IDX:
    EXR, EXI = 3, 4  # real and imaginary part of Ex
    EYR, EYI = 5, 6  # those of Ey
    EZR, EZI = 7, 8  # those of Ez

# get middle value for zpos
wrk = np.unique(zpos)
if len(wrk) % 2 == 0:
    # let the number of items [even]
    wrk = np.delete(wrk, max(wrk))
pickUpZvalue = np.median(wrk)

# parameters
SIZE_MAP_X = 30  # size of the image
SIZE_MAP_Y = 30
ZOOM_X = 15.0  #
ZOOM_Y = 15.0
SHIFT_X = 15.0  # to shift the center position
SHIFT_Y = 15.0
rmap = [[0.0 for yi in range(SIZE_MAP_Y)] for xi in range(SIZE_MAP_X)]

targetIdx = TARGET_IDX.EZI

# prepare map
for aline in zip(xpos, ypos, zpos, *Elist):
    ax, ay, az = aline[0], aline[1], aline[2]
    aTarget = aline[targetIdx]
    if abs(az - pickUpZvalue) > sys.float_info.epsilon:
        continue

    xidx = (SIZE_MAP_X * ax / ZOOM_X + SHIFT_X).astype(int)
    yidx = (SIZE_MAP_Y * ay / ZOOM_Y + SHIFT_Y).astype(int)

    if xidx < 0 or xidx >= SIZE_MAP_X:
        continue
    if yidx < 0 or yidx >= SIZE_MAP_Y:
        continue

    rmap[xidx][yidx] = aTarget  # overwrite

# draw map
wrkarr = np.array(rmap)
figmap = np.reshape(wrkarr, (SIZE_MAP_X, SIZE_MAP_Y))
plt.imshow(figmap, extent=(0, SIZE_MAP_X, 0, SIZE_MAP_Y), cmap=cm.jet)
plt.show()
```

### 結果

Exの実部
![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/15d29425-f794-f3d5-faf5-2b683e125a4b.png)

Exの虚部
![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/6cf34965-a9d9-1398-c5e4-56b46722faab.png)

Eyの実部
![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/d7a3d9c0-35c9-2ba3-ecf2-c4de424df06f.png)

Eyの虚部
![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/25467bc2-ffd1-0e90-420f-7daac1820323.png)

Ezの実部
![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/a0e20055-8cbd-a209-28f5-d5f8499e4a39.png)

Ezの虚部
![qiita.png](https://qiita-image-store.s3.amazonaws.com/0/32870/b46b5c7a-8274-4202-93ee-a5c1ab0dd09a.png)


## v0.3

`Elist`の取得方法について、[読みやすい実装方法を教えていただきました](http://qiita.com/7of9/items/5280690c9777d36a847a#comment-2ea9294d2d49e8af4cf7)。
情報感謝です。


`Elist = [src_data[:, idx] for idx in range(3, 9)]`から以下のように変更しました。
```
Elist = src_data.T[3:9]
```

Jupyter code.

```py:check_resultmap_170429
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import math
import sys
import matplotlib.pyplot as plt
import matplotlib.cm as cm

'''
v0.3 Mar. 03, 2017
   - [Elist] is extracted using matrix transposition
v0.2 Mar. 03, 2017
   - add [Elist] instead of each of [Exr, Exi, ...]
   - add [targetIdx] for selection of the target item
   - add enum [TARGET_IDX]
v0.1 Apr. 29, 2017
   - use snippet from [check_resultmap_170329.ipynb] v0.2
'''
# codingrule:PEP8

src_data = np.genfromtxt('LN-INPUT-CSV', delimiter=',')

xpos, ypos, zpos = src_data[:, 0], src_data[:, 1], src_data[:, 2]
# Exr, Exi, Eyr, Eyi, Ezr, Ezi
Elist = src_data.T[3:9]

class TARGET_IDX:
    EXR, EXI = 3, 4  # real and imaginary part of Ex
    EYR, EYI = 5, 6  # those of Ey
    EZR, EZI = 7, 8  # those of Ez

# get middle value for zpos
wrk = np.unique(zpos)
if len(wrk) % 2 == 0:
    # let the number of items [even]
    wrk = np.delete(wrk, max(wrk))
pickUpZvalue = np.median(wrk)

# parameters
SIZE_MAP_X = 30  # size of the image
SIZE_MAP_Y = 30
ZOOM_X = 15.0  #
ZOOM_Y = 15.0
SHIFT_X = 15.0  # to shift the center position
SHIFT_Y = 15.0
rmap = [[0.0 for yi in range(SIZE_MAP_Y)] for xi in range(SIZE_MAP_X)]

targetIdx = TARGET_IDX.EYR

# prepare map
for aline in zip(xpos, ypos, zpos, *Elist):
    ax, ay, az = aline[0], aline[1], aline[2]
    aTarget = aline[targetIdx]
    if abs(az - pickUpZvalue) > sys.float_info.epsilon:
        continue

    xidx = (SIZE_MAP_X * ax / ZOOM_X + SHIFT_X).astype(int)
    yidx = (SIZE_MAP_Y * ay / ZOOM_Y + SHIFT_Y).astype(int)

    if xidx < 0 or xidx >= SIZE_MAP_X:
        continue
    if yidx < 0 or yidx >= SIZE_MAP_Y:
        continue

    rmap[xidx][yidx] = aTarget  # overwrite

# draw map
wrkarr = np.array(rmap)
figmap = np.reshape(wrkarr, (SIZE_MAP_X, SIZE_MAP_Y))
plt.imshow(figmap, extent=(0, SIZE_MAP_X, 0, SIZE_MAP_Y), cmap=cm.jet)
plt.show()
```