7

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.

nbro
  • 13,796
  • 25
  • 99
  • 185
zenna
  • 8,838
  • 11
  • 69
  • 101

1 Answers1

4

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.

Mayou36
  • 3,893
  • 2
  • 16
  • 20
Frederic Shen
  • 161
  • 1
  • 9