如何交替连接pytorch张量?

How to alternatively concatenate pytorch tensors?

Pytorch 提供 API 连接张量,如 cat、stack。 但是它是否提供任何 API 来连接 pytorch 张量 或者

例如,

假设input1.shape = C*H*Wa1.shape = H\*Woutput.shape = (3C)*H*W

这可以使用循环来实现,但我想知道是否有任何 Pytorch API 可以做到这一点

我会尝试用小例子来做:

input1 = torch.full((3, 3), 1)
input2 = torch.full((3, 3), 2)
input3 = torch.full((3, 3), 3)

out = torch.concat((input1,input2, input3)).T.flatten()
torch.stack(torch.split(out, 3), dim=1).reshape(3,-1)

#output

tensor([[1, 2, 3, 1, 2, 3, 1, 2, 3],
        [1, 2, 3, 1, 2, 3, 1, 2, 3],
        [1, 2, 3, 1, 2, 3, 1, 2, 3]])