TensorFlow函数:tf.scatter_nd
tf.scatter_nd 函数 scatter_nd( indices, updates, shape, name=None ) 参见指南: 张量变换>分割和连接 根据indices将updates散布到新的(初始为零)张量。 根据索引对给定shape的零张量中的单个值或切片应用稀疏updates来创建新的张量。此运算符是 tf.gather_nd 运算符的反函数,它从给定的张量中提取值或切片。 警告:更新应用的顺序是非确定性的,所以如果indices包含重复项的话,则输出将是不确定的。 indices是一个整数张量,其中含有索引形成一个新的形状shape张量。indices的最后的维度可以是shape的最多的秩: indices.shape[ -1 ] <= shape.rank indices.shape[: -1 ] + shape[indices.shape[ -1 ]:] 最简单的分散形式是通过索引将单个元素插入到张量中。例如,假设我们想要在8个元素的1级张量中插入4个分散的元素。 在Python中,这个分散操作看起来像这样: indices = tf.constant([[ 4 ], [ 3 ], [ 1 ], [ 7 ]]) updates = tf.constant([ 9 , 10 , 11 , 12 ]) shape = tf.constant([ 8 ])