torch.Tensor.put_¶
- Tensor.put_(索引, 源, 累积=False) → Tensor ¶
将
source
中的元素复制到由index
指定的位置。为了索引的目的,将self
张量视为 1-D 张量。index
和source
需要具有相同数量的元素,但形状不一定相同。如果
accumulate
是True
,则将source
中的元素添加到self
中。如果累加为False
,则如果index
包含重复元素,则行为未定义。- 参数:
索引(LongTensor)- 指向 self 的索引
源(Tensor)- 包含要复制的值的张量
accumulate(布尔值)- 是否累加到 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]])