Division in batches of a 3D tensor

I have a 3D tensor of size say 100x5x2 and mean of the tensor across axis=1 which gives shape 100x2.
100 here is the batch size. Normally without batch, the division of tensor of shape 5x2 and 2 works perfectly but in the case of the 3D tensor with batch, I’m receiving error.

a = torch.rand(100,5,2)
b = torch.rand(100,2)

The size of tensor a (5) must match the size of tensor b (100) at non-singleton dimension 1.
How to divide these tensors such that my output is of shape 100x5x2 ? Something like bmm for division?

I think you can unsqueeze b so that a.dim() = b.dim()

import torch

n, m, p = 100,5,2

a = torch.rand(n, m, p)

b = torch.rand(n, p)

b = b.unsqueeze(dim=1) # n x 1 x p


Yeah that works. Thanks alot.