scatter_nd(indices,updates,shape,name=None)
根据indices将updates散布到新的(初始为零)张量。
最简单的分散形式是通过索引将单个元素插入到张量中。例如,假设我们想要在8个元素的1级张量中插入4个分散的元素。
indices = tf.constant([[4], [3], [1], [7]])
updates = tf.constant([9, 10, 11, 12])
shape = tf.constant([8])
scatter = tf.scatter_nd(indices, updates, shape)
with tf.Session() as sess:
print(sess.run(scatter))
输出如下:
[0, 11, 0, 10, 9, 0, 0, 12]