1

我试图使用此处提供的示例对两个张量进行逐元素乘法。

我的代码:

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'

谁能告诉我为什么我会收到这个错误?

4

3 回答 3

1

我得到了解决方案。而不是使用cmul,我需要使用mul。以下代码对我有用!

import torch

x = torch.Tensor([2, 3])
y = torch.Tensor([2, 1])
z = torch.mul(x, y)
print(z)

PS:我使用的是pytorch,而不是lua。

于 2017-03-22T03:19:40.483 回答
0

尝试:

z = x.cmul(y)

我认为cmul是类的方法Tensor,而不是函数......

PS:您提供的文档中的示例是用lua编写的,而不是python。

于 2017-03-21T23:01:59.577 回答
0

因为 Torch 没有这个方法。Cmul 是一个独立的类,它位于torch.legacy.nn将 Torch 作为参数 https://github.com/pytorch/pytorch/blob/master/torch/legacy/nn/CMul.py

于 2017-03-21T23:11:18.487 回答