Yes, but I would recommend to specify the dimension via tensor.squeeze(0) to make sure no other dimensions are removed in case they have a size of 1.
I don’t know which PyTorch version was originally used, but I thought t() did not work on >2D data. In any case, use tensor = tensor.permute(1, 2, 0) to create the [H, W, C] tensor and don’t use the deprecated .data attribute.
You are indexing the tensor, which will remove this dimension and you could slice it instead:

tensor = torch.randn(4, 4, 3)
out = tensor[:, :, 0]
print(out.shape)
> torch.Size([4, 4])

out = tensor[:, :, 0:1]
print(out.shape)
> torch.Size([4, 4, 1])

However, I don’t think the alpha channel should just be the red channel from the same image, so you might want to use torch.cat((torch.ones(H, W, 1), tensor), 2) instead.