如果没有进一步的上下文,我不知道为什么要更新
Variable
>>> x
<tf.Tensor: shape=(3, 5), dtype=float32, numpy=
array([[2., 2., 2., 0., 0.],
[1., 1., 1., 2., 0.],
[1., 0., 2., 0., 1.]], dtype=float32)>
>>> idx
<tf.Tensor: shape=(3, 5), dtype=bool, numpy=
array([[False, False, False, True, True],
[False, False, False, False, True],
[False, True, False, True, False]])>
>>> tf.where(idx, np.inf, tf.zeros_like(x, dtype=tf.float32))
<tf.Tensor: shape=(3, 5), dtype=float32, numpy=
array([[ 0., 0., 0., inf, inf],
[ 0., 0., 0., 0., inf],
[ 0., inf, 0., inf, 0.]], dtype=float32)>
>>> y = tf.Variable(tf.where(idx, np.inf, tf.zeros_like(x, dtype=tf.float32)), dtype=tf.float32)
>>> y
<tf.Variable 'Variable:0' shape=(3, 5) dtype=float32, numpy=
array([[ 0., 0., 0., inf, inf],
[ 0., 0., 0., 0., inf],
[ 0., inf, 0., inf, 0.]], dtype=float32)>