I found that Tensorflow provides scatter_update()
to assign values to the slice of a tensor in the 0 dimension. For example, if the tensor T
is three dimensional, I can assign value v[1, :, :]
to T[i, :, :]
.
a = tf.Variable(tf.zeros([10,36,36]))
value = np.ones([1,36,36])
d = tf.scatter_update(a,[0],value)
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print a.eval()
sess.run(d)
print a.eval()
But how to assign values v[1,1,:]
to T[i,j,:]
?
a = tf.Variable(tf.zeros([10,36,36]))
value1 = np.random.randn(1,1,36)
e = tf.scatter_update(a,[0],value1) #Error
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
print a.eval()
sess.rum(e)
print a.eval()
Is there any other function that TF provide or a simple way to do this?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…