torch.Tensor.index_fill_
- Tensor.index_fill_(dim, index, value) → Tensor
Fills the elements of the
selftensor with valuevalueby selecting the indices in the order given in.
Fills the elements of the self tensor with value value by
selecting the indices in the order given in .
Example:
>>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
>>> index = torch.tensor([0, 2])
>>> x.index_fill_(1, index, -1)
tensor([[-1., 2., -1.],
[-1., 5., -1.],
[-1., 8., -1.]])