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

Copies the elements from source into the positions specified by index. For the purpose of indexing, the self tensor is treated as if it were a 1-D tensor.

index and source need to have the same number of elements, but not necessarily the same shape.

If accumulate is True, the elements in source are added to self. If accumulate is False, the behavior is undefined if index contain duplicate elements.

  • index (LongTensor) – the indices into self

  • source (Tensor) – the tensor containing values to copy from

  • accumulate (bool) – whether to accumulate into 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]])


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources