two tensors in different dimensions, for example, A1=[B, H, V] A2=[H], how to contenate the two tensors to [B, H, V+1]?

This should work:

```
B, H, V = 2, 3, 4
A1 = torch.randn([B, H, V])
A2 = torch.randn([H])
A2 = A2[None, :, None].expand(B, -1, -1)
print(A2.shape)
out = torch.cat((A1, A2), dim=2)
print(out.shape)
torch.Size([2, 3, 5])
```

1 Like

Thanks. I have initialized

A2=torch.zeros(1,H,1)

A2 = A2.expand(B, -1, -1)

torch.cat((A2, A1), dim=2)