对变量中的单个值或切片应用稀疏加法。
用法
tf.raw_ops.ResourceScatterNdAdd(
ref, indices, updates, use_locking=True, name=None
)参数
-
refTensor类型为resource。资源句柄。必须来自 VarHandleOp。 -
indices一个Tensor。必须是以下类型之一:int32,int64。张量。必须是以下类型之一:int32、int64。参考的索引张量。 -
updates一个Tensor。张量。必须与 ref 具有相同的类型。要添加到 ref 的值的张量。 -
use_locking可选的bool。默认为True。一个可选的布尔值。默认为真。如果为 True,则分配将受锁保护;否则行为是未定义的,但可能表现出较少的争用。 -
name操作的名称(可选)。
返回
- 创建的操作。
ref 是排名为 P 的 Tensor ,而 indices 是排名为 Q 的 Tensor 。
indices 必须是整数张量,包含 ref 的索引。它必须是形状 [d_0, ..., d_{Q-2}, K] 其中 0 < K <= P 。
indices 的最内维(长度为 K )对应于沿 ref 的 K 第维的元素(如果是 K = P )或切片(如果是 K < P )的索引。
updates 是等级为 Q-1+P-K 的 Tensor,形状:
[d_0, ..., d_{Q-2}, ref.shape[K], ..., ref.shape[P-1]]
例如,假设我们要将 4 个分散的元素添加到 rank-1 张量到 8 个元素。在 Python 中,该添加看起来像这样:
ref = tf.Variable([1, 2, 3, 4, 5, 6, 7, 8], use_resource=True)
indices = tf.constant([[4], [3], [1], [7]])
updates = tf.constant([9, 10, 11, 12])
add = tf.scatter_nd_add(ref, indices, updates)
with tf.Session() as sess:
print sess.run(add)
对 ref 的更新结果如下所示:
[1, 13, 3, 14, 14, 6, 7, 20]
有关如何更新切片的更多详细信息,请参阅tf.scatter_nd。
相关用法
- Python tf.raw_ops.ResourceScatterNdSub用法及代码示例
- Python tf.raw_ops.ResourceScatterNdUpdate用法及代码示例
- Python tf.raw_ops.ResourceScatterMul用法及代码示例
- Python tf.raw_ops.ResourceScatterAdd用法及代码示例
- Python tf.raw_ops.ResourceScatterMax用法及代码示例
- Python tf.raw_ops.ResourceScatterMin用法及代码示例
- Python tf.raw_ops.ResourceScatterSub用法及代码示例
- Python tf.raw_ops.ResourceScatterUpdate用法及代码示例
- Python tf.raw_ops.ResourceScatterDiv用法及代码示例
- Python tf.raw_ops.ResourceGather用法及代码示例
- Python tf.raw_ops.Reshape用法及代码示例
- Python tf.raw_ops.ReadVariableXlaSplitND用法及代码示例
- Python tf.raw_ops.ReduceJoin用法及代码示例
- Python tf.raw_ops.Real用法及代码示例
- Python tf.raw_ops.Relu用法及代码示例
- Python tf.raw_ops.ReverseV2用法及代码示例
- Python tf.raw_ops.Reverse用法及代码示例
- Python tf.raw_ops.RegexFullMatch用法及代码示例
- Python tf.raw_ops.ReverseSequence用法及代码示例
- Python tf.raw_ops.RaggedGather用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.raw_ops.ResourceScatterNdAdd。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
