scatter_nd_sub
Example 1: subtraction at the second dimension, [0,1], which corresponding to a vector.
>>> ref = tf.Variable(tf.ones([2,3,3],tf.int32))
>>> indices = tf.constant([[0,1]])
>>> updates = tf.constant([[1,1,1]])
>>> init = tf.global_variables_initializer()
>>> sess.run(init)
>>> print(ref.eval())
[[[1 1 1]
[1 1 1]
[1 1 1]]
[[1 1 1]
[1 1 1]
[1 1 1]]]
>>> print(updates.eval())
[[1 1 1]]
>>> update = tf.scatter_nd_sub(ref,indices,updates)
>>> sess.run(update)
array([[[1, 1, 1],
[0, 0, 0],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]], dtype=int32)
Example 2: subtraction at the third dimension, [0,1,2], which points to a single element.
>>> ref = tf.Variable(tf.ones([2,3,3],tf.int32))
>>> indices = tf.constant([[0,1,2]])
>>> updates = tf.constant([1])
>>> init = tf.global_variables_initializer()
>>> sess.run(init)
>>> print(ref.eval())
[[[1 1 1]
[1 1 1]
[1 1 1]]
[[1 1 1]
[1 1 1]
[1 1 1]]]
>>> print(updates.eval())
[1]
>>> update = tf.scatter_nd_sub(ref,indices,updates)
>>> sess.run(update)
array([[[1, 1, 1],
[1, 1, 0],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]], dtype=int32)
TensorFlow中scatter_nd_sub用法示例
本文通过两个具体实例介绍了如何使用TensorFlow中的scatter_nd_sub操作进行张量元素的减法更新。第一个例子展示了如何在第二维度上进行向量的减法操作;第二个例子则演示了如何在第三维度上的特定位置进行单个元素的减法更新。
16万+

被折叠的 条评论
为什么被折叠?



