快捷方式

torch.Tensor.put_

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

source 中的元素複製到 index 指定的位置。為了索引的目的,self 張量被視為如同它是 1 維張量。

indexsource 需要有相同數量的元素,但不一定需要相同的形狀。

如果 accumulateTrue,則 source 中的元素會加到 self。如果 accumulate 為 False,如果 index 包含重複的元素,則行為未定義。

參數
  • index (LongTensor) – self 的索引

  • source (Tensor) – 包含要複製的值的張量

  • accumulate (bool) – 是否累積到 self 中

範例

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

文件

取得 PyTorch 的完整開發人員文件

檢視文件

教學

取得初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源