I have two matrices of sizes (32, 512, 7,7) and (32, 512)  respectively, where 32 is the batch size and 512 is the channel size. Let us call them A and B.
Now what I need to do is this:
        for i in range(batch_size):
            for j in range(channel_size):
                A[i,j,:,:]=A[i,j,:,:]*B[i,j]

In other words, I want to have each elements of the 7x7 matrix (of i th batch and j th channel) multiplied by the corresponding value from B matrix’s corresponding scalar for i th batch and j th channel number.
Using for loops becomes higly inefficient when I have to increasing batch size.
Is there any other way of doing the same?
Any help will be appreciated.