属性错误:模块“torch”没有属性“cmul”

问题描述 投票:0回答:3

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

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'

谁能告诉我为什么会出现此错误?

pytorch
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。


0
投票
torch.legacy.nn

,它以 Torch 作为参数

https://github.com/pytorch/pytorch/blob/master/torch/legacy/nn/CMul.py


0
投票

z = x.cmul(y)

我认为
cmul

是类

Tensor
的方法,而不是函数...

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

© www.soinside.com 2019 - 2024. All rights reserved.