How can I do element-wise batch matrix multiplication?
I have two tensors of shape (16, 300) and (16, 300) where 16 is the batch size and 300 is some representation vector. I want to compute the element-wise batch matrix multiplication to produce a matrix (2d tensor) whose dimension will be (16, 300). So, in short I want to do 16 element-wise multiplication of two 1d-tensors. I can do this using a for loop but is there any way, I can do it using torch API?
wasiahmad
jekbradbury
wasiahmad
What is batch element-wise multiplication? Can you show me your for loop?
smth
If you have tensor a and b both of shape (16, 300) and you want to get a tensor of shape (16, 300) by element-wise multiplication, I assume you can do a*b?
ZeweiChu
wasiahmad
apaszke
wangg12
jekbradbury
wangg12
we dont have auto-broadcasting yet.
smth
Could we use just if A is matrix and v is a vector ? It worked for me but i am not sure if the BP works fine.
dpappas
wandering007
I solved like this, but maybe I am late to the party: <SCODE>def bmul(vec, mat, axis=0):
    mat = mat.transpose(axis, -1)
    return (mat * vec.expand_as(mat)).transpose(axis, -1)
<ECODE>
e.pignatelli