9

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
  • 15,395
  • 32
  • 113
  • 196
zenna
  • 9,006
  • 12
  • 73
  • 101

1 Answers1

6

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
  • 4,613
  • 2
  • 17
  • 20
Frederic Shen
  • 181
  • 2
  • 9