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]]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.