快捷键

torch.Tensor.index_fill_

Tensor.index_fill_(dim, index, value) Tensor

通过选择在 index 中给出的顺序,将值 value 填充到 self 张量的元素中。

参数:
  • dim(int)- 沿着哪个维度进行索引

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

  • 值(浮点数)- 要填充的值

示例::
>>> 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.]])

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源