torch.Tensor.masked_scatter

Tensor.masked_scatter(mask, source_tensor) Tensor

torch.Tensor.masked_scatter_() 的独立版本

注意

输入 selfmask 进行广播。

示例

>>> self = torch.tensor([0, 0, 0, 0, 0])
>>> mask = torch.tensor([[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]], dtype=torch.bool)
>>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
>>> self.masked_scatter(mask, source)
tensor([[0, 0, 0, 0, 1],
        [2, 3, 0, 4, 5]])
本页目录