0

I want to change the value in tensor t to a where its value is b, which can be expressed in numpy as:

t[t == b] = a
huangbiubiu
  • 1,252
  • 20
  • 37

1 Answers1

6

This creates a new tensor as specified:

t2 = tf.where( tf.equal( b, t ), a * tf.ones_like( t ), t )

If you want to change the value of t you can only do that if t is a variable, not a simple tensor, and then you can use assign:

tf.assign( t, t2 )
Peter Szoldan
  • 4,792
  • 1
  • 14
  • 24