torch.Tensor.put_¶
- Tensor.put_(index, source, accumulate=False) Tensor¶
將源張量 (
source) 中的元素複製到由索引 (index) 指定的位置。為了索引方便,self張量被視為一維張量處理。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]])