快捷方式

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

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源