我想将张量散布在行的粒度中。
例如,考虑
Input = torch.tensor([[2, 3], [3, 4], [4, 5]])
我想分散
S = torch.tensor([[1,2],[1,2]])
至索引
I = torch.tensor([0,2])
我希望输出为torch.tensor([[1, 2], [3, 4], [1, 2]])
。
[这里S[0]
分散到输入[I[0]]
,类似地S[1]
分散到Input[I[1]]
我该如何实现?我不是在循环S
中的行,而是在寻找一种更有效的方法。
执行input[I] = S
示例:
input = torch.tensor([[2, 3], [3, 4], [4, 5]])
S = torch.tensor([[1,2],[1,2]])
I = torch.tensor([0,2])
input[I] = S
input
tensor([[1, 2],
[3, 4],
[1, 2]])