評價此頁

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