pytorch中沿行的散射张量

问题描述 投票:1回答:1

我想将张量散布在行的粒度中。

例如,考虑

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中的行,而是在寻找一种更有效的方法。

python tensorflow pytorch tensor scatter
1个回答
1
投票

执行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]])
© www.soinside.com 2019 - 2024. All rights reserved.