快捷方式

torch.Tensor.index_fill_

Tensor.index_fill_(dim, index, value) Tensor

透過依序選取 index 中給定的索引,以數值 value 填滿 self tensor 的元素。

參數
  • dim (int) – 要沿其建立索引的維度

  • index (LongTensor) – 要填入的 self tensor 的索引

  • 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 完整的開發者文件

查看文件

教學

取得初學者和進階開發者的深入教學

查看教學

資源

尋找開發資源並獲得問題解答

查看資源