torch.Tensor.masked_scatter_¶
- Tensor.masked_scatter_(mask, source)¶
- Copies elements from - sourceinto- selftensor at positions where the- maskis True. Elements from- sourceare copied into- selfstarting at position 0 of- sourceand continuing in order one-by-one for each occurrence of- maskbeing True. The shape of- maskmust be broadcastable with the shape of the underlying tensor. The- sourceshould have at least as many elements as the number of ones in- mask.- Parameters
- mask (BoolTensor) – the boolean mask 
- source (Tensor) – the tensor to copy from 
 
 - Note - The - maskoperates on the- selftensor, not on the given- sourcetensor.- Example - >>> self = torch.tensor([[0, 0, 0, 0, 0], [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]])