[英]pytorch multiply 4*1 matrix and 1 size variable occur error
import torch
from torch.autograd import Variable
import numpy as np
x = np.transpose(np.array([[1, 2, 3, 4]]))
a = Variable(torch.rand(1), requires_grad=True)
print(a * x) # error!
I want result like x = [[2][4][6][8]] if a = 2 如果a = 2,我想要x = [[2] [4] [6] [8]]这样的结果
is there any solution? 有什么解决办法吗?
What you are looking for is the dot scalar product in matrix multiplication. 您正在寻找的是矩阵乘法中的点标量积。
try: 尝试:
x = np.transpose(np.array([[1, 2, 3, 4]]))
a = 2
x.dot(a)
This outputs a matrix [[2][4][6][8]] 输出矩阵[[2] [4] [6] [8]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.