Dividing 4D Variable by a 2D Varialbe

Hello Everyone,

I was trying to divide a 4-dimensional Variable by 2-dimensional Variable.

the first Variable size is [B,C,H,W]. and the second Variable size is [B,C].

I want all the values a single [H,W] map to be divided by a single value from the [B,C]

is there any good way to this. Thanks

You could add single dimensions, so that broadcasting will take care of this:

B, C, H, W = 1, 3, 24, 24
a = torch.randn(B, C, H, W)
b = torch.ones(B, C, 1, 1) / 2.
c = a / b
print(a, c)

Thanks @ptrblck. It worked :slight_smile: