I wanna find some torch function ;

I wanna find some torch function like this:

input : a = [[1,2,3,4], [5,6,7,8]], b = [[0,0,0,0],[0,0,0,0]]
output : c = [[[1,0],[2,0],[3,0],[4,0]],[[5,0],[6,0],[7,0],[8,0]]]

Does this kind of function exist in torch?

Yes, you can use torch.stack:

a = torch.tensor([[1,2,3,4], [5,6,7,8]])
b = torch.tensor([[0,0,0,0],[0,0,0,0]])

c = torch.tensor([[[1,0],[2,0],[3,0],[4,0]],[[5,0],[6,0],[7,0],[8,0]]])
print(c)
> tensor([[[1, 0],
           [2, 0],
           [3, 0],
           [4, 0]],

          [[5, 0],
           [6, 0],
           [7, 0],
           [8, 0]]])

d = torch.stack((a, b), dim=2)
print(d)
> tensor([[[1, 0],
           [2, 0],
           [3, 0],
           [4, 0]],

          [[5, 0],
           [6, 0],
           [7, 0],
           [8, 0]]])

oh, that’s exactly what I want.

thanks so much :).