Appending dimension only

I have two tensors a = torch.Size([1, 566757, 3]) and b = torch.Size([1, 566757, 16]) and want the last feature dimension to be merged to result in tensor c = torch.Size([1, 566757, 19]).

Will appreciate the help if any one can suggestion a work around.

Thanks

You could use torch.cat.

Example

import torch

a = torch.randn(5, 10, 1)
b = torch.randn(5, 10, 6)

torch.cat((a, b), dim=2).shape
1 Like

that works, many thanks @arunppsg