1. mul
按元素相乘,存在广播机制,看下面这个例子:
import torch
a = torch.tensor([[[1,2],[2,3],[3,4],[4,5],[5,6]]])
b = torch.tensor([[[1],[2],[3],[4],[5]]])
c= torch.mul(a,b)
print("a shape: ", a.shape)
print("b shape: ", b.shape)
print("c shape: ", a.shape)
print("c: ", c)
打印结果:
a shape: torch.Size([1, 5, 2])
b shape: torch.Size([1, 5, 1])
c shape: torch.Size([1, 5, 2])
c: tensor([[[ 1, 2],
[ 4, 6],
[ 9, 12],
[16, 20],
[25, 30]]])