How to add a 2d tensor to every 2d tensor from a 3d tensor
I'm trying to add a 2d tensor to every 2d tensor from a 3d tensor.
Let's say i have a  tensor a with (2,3,2) shape and a tensor b with (2,2) shape.

a = [[[1,2],
      [1,2],
      [1,2]],
     [[3,4],
      [3,4],
      [3,4]]]

b = [[1,2], [3,4]]

#the result i want to get
a[:, 0, :] + b
a[:, 1, :] + b
a[:, 2, :] + b


I wanna know if there is a method in pytorch that can do this.

The most efficient way of doing this would be to add an extra second dimension to b and use broadcasting to add:

a = torch.Tensor([[[1,2],[1,2],[1,2]],[[3,4],[3,4],[3,4]]])
b = torch.Tensor([[1,2],[3,4]])
a += b.unsqueeze(1)

