我想知道是否有更简单(或更有效)的方式来执行平均定心操作?
目前,我正在执行以下操作:
data = torch.Tensor{
{40, 6, 4},
{44, 10, 4},
{46, 12, 5},
{48, 14, 7},
{52, 16, 9},
{58, 18, 12},
{60, 22, 14},
{68, 24, 20},
{74, 26, 21},
{80, 32, 24}
}
x = torch.Tensor(data:size(2)):fill(0)
centeredData = torch.Tensor(data:size())
x:addmv(1/data:size(1), data:t(), torch.ones(data:size(1)))
torch.addr(centeredData:t(), data:t(), -1, x, torch.ones(data:size(1)))
-- double check it's mean centered:
assert(torch.mean(centeredData,1) == torch.zeros(1,data:size(2)), "not centered")
答案 0 :(得分:2)
mean = data:mean(1)
data:add(-1, mean:expandAs(data))