AttributeError:模块'火炬'没有属性' cmul'

时间:2017-03-21 22:54:47

标签: torch pytorch

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

我的代码:

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'

有人能告诉我为什么会收到此错误吗?

3 个答案:

答案 0 :(得分:0)

尝试:

z = x.cmul(y)

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

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

答案 1 :(得分:0)

因为火炬没有这种方法。 Cmul是一个独立的类,它位于<?php query_posts('cat=5&showposts=1'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile; endif; ?> <?php wp_reset_query(); ?> ,它以Torch作为参数 Example

答案 2 :(得分:0)

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

import torch

x = torch.Tensor([2, 3])
y = torch.Tensor([2, 1])
z = torch.mul(x, y)
print(z)
PS:我正在使用pytorch,而不是lua。

相关问题