对变量中的单个值或切片应用稀疏减法。
用法
tf.compat.v1.scatter_nd_sub(
ref, indices, updates, use_locking=False, name=None
)参数
-
ref一个可变的Tensor。必须是以下类型之一:float32,float64,int32,uint8,int16,int8,complex64,int64,qint8,quint8,qint32,bfloat16,uint16,complex128,half,uint32,uint64。一个可变张量。应该来自变量节点。 -
indices一个Tensor。必须是以下类型之一:int32,int64。参考的索引张量。 -
updates一个Tensor。必须与ref具有相同的类型。要添加到 ref 的更新值的张量。 -
use_locking可选的bool。默认为False。一个可选的布尔值。默认为真。如果为 True,则分配将受锁保护;否则行为是未定义的,但可能表现出较少的争用。 -
name操作的名称(可选)。
返回
-
一个可变的
Tensor。具有与ref相同的类型。
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]]
例如,假设我们想从具有 8 个元素的 rank-1 张量中减去 4 个分散元素。在 Python 中,该更新将如下所示:
ref = tf.Variable([1, 2, 3, 4, 5, 6, 7, 8])
indices = tf.constant([[4], [3], [1] ,[7]])
updates = tf.constant([9, 10, 11, 12])
op = tf.compat.v1.scatter_nd_sub(ref, indices, updates)
with tf.compat.v1.Session() as sess:
print sess.run(op)
对 ref 的更新结果如下所示:
[1, -9, 3, -6, -6, 6, 7, -4]
有关如何更新切片的更多详细信息,请参阅tf.scatter_nd。
相关用法
- Python tf.compat.v1.scatter_nd_update用法及代码示例
- Python tf.compat.v1.scatter_nd_add用法及代码示例
- Python tf.compat.v1.scatter_min用法及代码示例
- Python tf.compat.v1.scatter_add用法及代码示例
- Python tf.compat.v1.scatter_div用法及代码示例
- Python tf.compat.v1.scatter_update用法及代码示例
- Python tf.compat.v1.scatter_mul用法及代码示例
- Python tf.compat.v1.scatter_sub用法及代码示例
- Python tf.compat.v1.scatter_max用法及代码示例
- Python tf.compat.v1.scalar_mul用法及代码示例
- Python tf.compat.v1.scan用法及代码示例
- Python tf.compat.v1.strings.length用法及代码示例
- Python tf.compat.v1.summary.merge用法及代码示例
- Python tf.compat.v1.size用法及代码示例
- Python tf.compat.v1.summary.FileWriter用法及代码示例
- Python tf.compat.v1.space_to_batch用法及代码示例
- Python tf.compat.v1.string_split用法及代码示例
- Python tf.compat.v1.squeeze用法及代码示例
- Python tf.compat.v1.set_random_seed用法及代码示例
- Python tf.compat.v1.sparse_to_dense用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.scatter_nd_sub。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
