以下是如何应用布尔索引并有条件地将值赋给变量的示例:
a = tf.Variable(initial_value=[0, 0, 4, 6, 1, 2, 4, 0])
mask = tf.greater_equal(a, 2) # [False False True True False True True False]
indexes = tf.where(mask) # [[2] [3] [5] [6]], shape=(4, 1)
b = tf.scatter_update(a, mask, tf.constant(1500))
output:
[ 0, 0, 1500, 1500, 1, 1500, 1500, 0]