torch.Tensor.Tensor.masked_scatter
Copies elements from source into self tensor at positions where mask is True.
Elements are copied from source in order, filling the positions where mask is True. The source tensor should have at least as many elements as there are True values in mask.
Parameters
maskTensor- Boolean mask tensor (broadcastable to self shape)
sourceTensor- Source tensor to copy values from
Returns
Tensor<S, D, Dev>– New tensor with source values scattered at masked positionsExamples
const x = torch.zeros(5);
const mask = torch.tensor([true, false, true, false, true]);
const source = torch.tensor([1, 2, 3]);
x.masked_scatter(mask, source); // [1, 0, 2, 0, 3]