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

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]]
