Reputation: 37691
I was trying to do element-wise multiplication of two tensors using the example provided here.
My code:
import torch
x = torch.Tensor([2, 3])
y = torch.Tensor([2, 1])
z = torch.cmul(x, y)
print(z)
It is giving me the following error.
AttributeError: module 'torch' has no attribute 'cmul'
Can anyone tell me why I am getting this error?
Upvotes: 1
Views: 2983
Reputation: 37691
I got the solution. Instead of using cmul
, I need to use mul
. The following code worked for me!
import torch
x = torch.Tensor([2, 3])
y = torch.Tensor([2, 1])
z = torch.mul(x, y)
print(z)
PS: I was using pytorch, not lua.
Upvotes: 1
Reputation: 606
try:
z = x.cmul(y)
I think cmul
is a method of the class Tensor
, not a function...
PS: The exemple in the documentation you gave is written in lua, not python.
Upvotes: 0
Reputation: 1543
Because Torch doesnt have this method.
Cmul is a class on its own which is located at torch.legacy.nn
which takes Torch as arguments
https://github.com/pytorch/pytorch/blob/master/torch/legacy/nn/CMul.py
Upvotes: 0