torch.Tensor.index_fill_¶ Tensor.index_fill_(dim, index, value) → 张量¶ 通过选择在 index 中给定的顺序的索引,用值 value 填充 self 张量的元素。 Parameters dim (int) – 沿此维度进行索引 索引 (LongTensor) – 要填充的 self 张量的索引 值 (浮点数) – 要填充的值 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.]])