In tensorflow you cannot update the tensor, but you can update the variable.
The scatter_update can only update the first dimension of a variable. You should always pass the reference tensor to update the scattering ( a instead of a[line] ).
Here's how you can update the first element of a variable:
import tensorflow as tf g = tf.Graph() with g.as_default(): a = tf.Variable(initial_value=[[0, 0, 0, 0],[0, 0, 0, 0]]) b = tf.scatter_update(a, [0, 1], [[1, 0, 0, 0], [1, 0, 0, 0]]) with tf.Session(graph=g) as sess: sess.run(tf.initialize_all_variables()) print sess.run(a) print sess.run(b)
Output:
[[0 0 0 0] [0 0 0 0]] [[1 0 0 0] [1 0 0 0]]
But, to change the whole tensor again, it would be faster to assign a completely new one.
fabrizioM
source share