我试图使用此处提供的示例对两个张量进行逐元素乘法。 我的代码:
import torch
x = torch.Tensor([2, 3])
y = torch.Tensor([2, 1])
z = torch.cmul(x, y)
print(z)
它给了我以下错误。
AttributeError: module 'torch' has no attribute 'cmul'
谁能告诉我为什么会出现此错误?
cmul
,而不是使用
mul
。以下代码对我有用!import torch
x = torch.Tensor([2, 3])
y = torch.Tensor([2, 1])
z = torch.mul(x, y)
print(z)
PS:我使用的是pytorch,而不是lua。
z = x.cmul(y)
我认为
cmul
是类
Tensor
的方法,而不是函数...PS:您给出的文档中的示例是用lua编写的,而不是python。