Multiply feature map by a learnable scalar

Make your scalar a Variable containing a 1D tensor, and use the expand_as function.

matrix = Variable(torch.rand(3,3))
scalar = Variable(torch.rand(1), requires_grad=True)
output = matrix * scalar.expand_as(matrix)
7 Likes