Concatenate Tensors with different dimension

Hi everyone,

torch.rand(1,4,2,2)
tensor([[[[0.2244, 0.5357],
          [0.6145, 0.6231]],

         [[0.0133, 0.0747],
          [0.2936, 0.9928]],

         [[0.8611, 0.5119],
          [0.7976, 0.1552]],

         [[0.7479, 0.0291],
          [0.3519, 0.8065]]]])

I want to add an artificial class to my prediction with zero as prob, so i want to add a zero tensor of dim(2,2).

I want a result like this :

tensor([[[[0.2244, 0.5357],
          [0.6145, 0.6231]],

         [[0.0133, 0.0747],
          [0.2936, 0.9928]],

         [[0.8611, 0.5119],
          [0.7976, 0.1552]],

         [[0.7479, 0.0291],
          [0.3519, 0.8065]],
         
         [[0.0,0.0],
           [0.0,0.0]]
]])

with now a tensor of size (1,5,2,2)

How can i do, when I use stack or cat it says this error :

RuntimeError: stack expects each tensor to be equal size, but got [1, 4, 2, 2] at entry 0 and [2, 2] at entry 1

How can I do to overcome the problem of the dimension, is there a solution ?

Thank you for your help !

torch.cat((t,torch.zeros(2,2).unsqueeze(dim=0).unsqueeze(dim=0)),dim=1)

Works !