乘张量 lua

Multiply tensor lua

我是 lua、

的新手

为什么下面的代码不起作用?

local data = torch.Tensor(100, 4)
--data tensor is read from file
local w = torch.Tensor(1, 4):zero()
local tmp = w * data[5]:t()

data[5] 是一维张量和 transpose only works for 2-D tensors. So you can use the indexing 运算符,如下所示以获得额外的维度:

 -- matrix-matrix operation: result is a 1x1 tensor
 local tmp = w * data[{{5}}]:t()

或者 squeeze w 的第一个单例维度:

 -- dot prod between 1D tensors: result is a number
 local tmp = w:squeeze() * data[5]