Append tensor to each element of another tensor
I have a pytorch tensor: x = torch.zeros(2, 2), and another tensor of variable values: item = torch.tensor([[1, 2], [3, 4]]), I am just giving this tensor for example.
I would like add the item tensor as each element of the x tensor, such that
x = [[item, item], 
     [item, item]]

So x is a tensor with tensors inside it.
I have tried assigning item directly to x, but got an error: RuntimeError: The expanded size of the tensor must match the existing size at non-singleton dimension

use torch.repeat(),
your target_tensor shape will be torch.Size([2, 2, 2, 2]).
item tensor shape is already torch.Size([2, 2])
use :
target_tensor = item.repeat(2, 2, 1, 1)

the first two parameters of the repeat() function are x's shape
