评价此页

torch.Tensor.put_#

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

source 中的元素复制到 index 指定的位置。为了索引的目的,self 张量被视为 1-D 张量。

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]])