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