How to add 3 channels in one extra dims of tensor?

Hello, I have a tensor with size of BxCxHxW. I want to obtain the new tensor with size of Bx3xCxHxW, How can I do it? I have used unsqueeze(1) function but it only provides Bx1xCxHxW. Thanks

Edit: I also think another solution may works

B= torch.cat([torch.zeros(A.size()).unsqueeze(1),torch.zeros(A.size()).unsqueeze(1),torch.zeros(A.size()).unsqueeze(1)]

Hi,

What do you want these 2 extra dimensions to contain?

Just zero value. …

This should do it then to create a tensor of same type and on the same device as A.
You can change the dtype and device arguments if you need a different type and/or device.

size = list(A.size())
size.insert(1, 3)
B = torch.zeros(size, dtype=A.dtype, device=A.device)
1 Like