Hadamard Product Libtorch

How to get Hadamard product aka element-wise mul of two Libtorch torch tensors in C++?

@Hiperdyne19012
You can just use operator *
eg. torch::Tensor a = torch::tensor(2, 3, 4)
torch::Tensor b = torch::tensor(2, 3, 4)
torch c = a * b;
c will be [4, 9, 16]

1 Like