【发布时间】:2018-09-10 15:13:05
【问题描述】:
我想在 Tensorflow 中更新一个变量,因此我使用 tf.while_loop 如下:
a = tf.Variable([0, 0, 0, 0, 0, 0] , dtype = np.int16)
i = tf.constant(0)
size = tf.size(a)
def condition(i, size, a):
return tf.less(i, size)
def body(i, size, a):
a = tf.scatter_update(a, i , i)
return [tf.add(i, 1), size, a]
r = tf.while_loop(condition, body, [i, size, a])
这是我正在尝试做的一个例子。发生的错误是AttributeError: 'Tensor' object has no attribute '_lazy_read'。在 Tensorflow 中更新变量的适当方法是什么?
【问题讨论】:
标签: python tensorflow