I have a tensor in pytorch with size
torch.Size([1443747, 128]). Let’s name it tensor
A. In this tensor, 128 represents a batch size. I have another 1D tensor with size
torch.Size(). Let’s call it
B. I want to do element wise multiplication of B with A, such that B is multiplied with all 128 columns of tensor
A (obviously in an element wise manner). In other words, I want to broadcast the element wise multiplication along
How can I achieve this in pytorch?
It I didn’t have a batch size involved in the tensor A (
batch size = 1), then normal
* operator would do the multiplication easily.
A*B then would have generated resultant tensor of size
torch.Size(). However, I don’t understand why pytorch is not broadcasting the tensor multiplication along dimension 1? Is there any way to do this?
What I want is,
B should be multiplied with all 128 columns of
A in an element wise manner. So, the resultant tensors’ size would be