回答編集履歴

2

d

2019/08/13 06:02

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -65,3 +65,43 @@
65
65
  print(ret) # [ 0 2 4 6 8 10 12 14 16 18]
66
66
 
67
67
  ```
68
+
69
+
70
+
71
+ 同様に tf.variable の初期値に numpy 配列を設定できます。
72
+
73
+
74
+
75
+ ```python
76
+
77
+ import numpy as np
78
+
79
+ import tensorflow as tf
80
+
81
+
82
+
83
+ x = tf.placeholder(tf.int64, (10,))
84
+
85
+ h = tf.Variable(np.arange(10))
86
+
87
+ y = x + h
88
+
89
+
90
+
91
+ data = np.arange(10)
92
+
93
+
94
+
95
+ with tf.Session() as sess:
96
+
97
+ # 初期化必須!
98
+
99
+ sess.run(tf.global_variables_initializer())
100
+
101
+
102
+
103
+ ret = sess.run(y, feed_dict={x: data})
104
+
105
+ print(ret) # [ 0 2 4 6 8 10 12 14 16 18]
106
+
107
+ ```

1

d

2019/08/13 06:02

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -48,7 +48,7 @@
48
48
 
49
49
  x = tf.placeholder(tf.int64, (10,))
50
50
 
51
- c = tf.constant(np.arange(10))
51
+ c = tf.constant(np.arange(10)) # numpy 配列から定数を作成する。
52
52
 
53
53
  y = x + c
54
54