Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update elements of a tensor using indices?

I'm looking for an "update" function that takes in a tensor t1, some indices and values and returns a new tensor t2, which is t1 but with the values at the indices changed accordingly.

This seems like the most basic of functions, but I do not see it in the documentation.

What I do see is tf.scatter_update, which updates values in a Variable: in a way it is what I want. I could conceivably construct a Variable for t2 (would this work?), but t2 is not supposed to be a stateful variable and I would be populating it with arbitrary initial values.

Or, I could manually construct a Python nested list adding each element of t1 and t2 individually, then calling tf.convert_to_tensor. I could be wrong, but this seems likely to horribly inefficient.

like image 754
zenna Avatar asked Sep 10 '16 11:09

zenna


1 Answers

You can try tf.scatter_update or tf.scatter_add to update tensor value according to indices.

See the question adjust-single-value-within-tensor-tensorflow for a reference.

like image 62
Frederic Shen Avatar answered Sep 30 '22 13:09

Frederic Shen