torch.Tensor.put_¶
- Tensor.put_(index, source, accumulate=False) Tensor ¶
將
source
中的元素複製到index
指定的位置。為了索引的目的,self
張量被視為如同它是 1 維張量。index
和source
需要有相同數量的元素,但不一定需要相同的形狀。如果
accumulate
為True
,則source
中的元素會加到self
。如果 accumulate 為False
,如果index
包含重複的元素,則行為未定義。範例
>>> 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]])