评价此页

torch.Tensor.put_#

Tensor.put_(index, source, accumulate=False) Tensor#

source 中的元素复制到由 index 指定的位置。为进行索引,self 张量被视为一维张量。

indexsource 需要具有相同数量的元素,但不必具有相同的形状。

如果 accumulateTrue,则将 source 中的元素加到 self 上。如果 accumulate 为 False,则在 index 包含重复元素时,行为是不确定的。

参数:
  • index (LongTensor) – self 中的索引

  • source (Tensor) – 包含要复制的值的张量

  • accumulate (bool, optional) – 是否累加到 self 中。默认值:False

示例

>>> src = torch.tensor([[4, 3, 5],
...                     [6, 7, 8]])
>>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
tensor([[  4,   9,   5],
        [ 10,   7,   8]])