TensorFlow - 在张量中将 1 更改为 0

Hua*_*eng 0 python numpy tensorflow

我想改变张量的值ta哪里它的价值是b,它可以在numpy的作为来表示:

t[t == b] = a
Run Code Online (Sandbox Code Playgroud)

Pet*_*dan 6

这将创建一个指定的新张量:

t2 = tf.where( tf.equal( b, t ), a * tf.ones_like( t ), t )
Run Code Online (Sandbox Code Playgroud)

如果你想改变你的值,t你只能这样做 ift是一个变量,而不是一个简单的张量,然后你可以使用assign

tf.assign( t, t2 )
Run Code Online (Sandbox Code Playgroud)