I want to fill a data tensor with a float given some index tensor. It seems very simple and almost like masked_fill_
, but my index tensor doesn’t have the same size as the data tensor. Can you please take a quick look at it? I am looking for something like x.index_fill_(index, 42)
in the following example:
x = torch.Tensor([[0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
index = torch.LongTensor([[1, 3], [0, 4], [2, 3]])
# After indexed fill
x = torch.Tensor([[0, 42, 2, 42, 4],
[42, 6, 7, 8, 42],
[10, 11, 42, 42, 14]])