Rate this Page

torch.Tensor.put_#

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

Copies the elements fromsource into the positions specified byindex. For the purpose of indexing, theself tensor is treated as ifit were a 1-D tensor.

index andsource need to have the same number of elements, but not necessarilythe same shape.

Ifaccumulate isTrue, the elements insource are added toself. If accumulate isFalse, the behavior is undefined ifindexcontain duplicate elements.

Parameters
  • index (LongTensor) – the indices into self

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

  • accumulate (bool,optional) – whether to accumulate into self. Default:False

Example:

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