torch.Tensor.index_fill_

Tensor.index_fill_(dim, index, value) Tensor

根据index中给出的顺序选择索引,并用value填充self张量的元素。

参数
  • dim (int) - 需要进行索引的维度

  • index (LongTensor) – 指定要填充的 self 张量的索引

  • value (float) — 填充的值

示例:
>>> 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.]])
本页目录