動作環境
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
v0.1 http://qiita.com/7of9/items/8b43357bcaea1f1bce4b
v0.2
- csvファイル出力追加
- 関連してcalcOutput()をnumpy.arrayにて出力するように変更
参考: http://qiita.com/richi40/items/6b3af6f4b00d62dbe8e1
code
Jupyterコード
in100_out100.ipynb
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
'''
v0.2 Jan. 14, 2017
- sa() return in numpy.array
- add saveToCsvFile()
v0.1 Jan. 14, 2017
- add calcOutput()
- add showIn2D()
- show 1d in 2d format
'''
'''
codingrule:PEP8
'''
XDIM = 10
YDIM = 10
INDIM = XDIM * YDIM
def saveToCsvFile(data_1d, filename):
wrk_1d = data_1d.reshape(1,INDIM)
np.savetxt(filename, wrk_1d, delimiter=',')
def calcOutput(in_1d):
len_1d = XDIM * YDIM
out_1d = [0.0] * len_1d
for idx in range(0, in_1d.size):
out_1d[idx] = in_1d[len_1d - idx - 1]
return np.array(out_1d)
def showIn2D(data_1d):
# print(data_1d)
data_2d = np.reshape(data_1d, (XDIM, YDIM))
plt.imshow(data_2d, extent=(0, XDIM, 0, YDIM), cmap=cm.gist_rainbow)
plt.show()
if __name__ == '__main__':
in_1d = np.random.rand(INDIM)
showIn2D(in_1d)
out_1d = calcOutput(in_1d)
showIn2D(out_1d)
saveToCsvFile(in_1d, 'test_in.csv')
saveToCsvFile(out_1d, 'test_out.csv')
結果
$ cut -c 1-200 test_in.csv
3.757247572810928915e-04,2.261566444672071796e-01,5.665968126413482020e-01,5.869499141590118763e-01,6.474665738698877071e-01,8.782973384764291014e-01,9.808027016657328012e-01,9.172719111087710431e-01,
$ cut -c 2300-2500 test_out.csv
,9.172719111087710431e-01,9.808027016657328012e-01,8.782973384764291014e-01,6.474665738698877071e-01,5.869499141590118763e-01,5.665968126413482020e-01,2.261566444672071796e-01,3.757247572810928915e-04