火炬连接 1D 到 2D 张量

时间:2021-04-26 13:19:57

标签: vector pytorch concatenation

我对 concat 2 张量有疑问,

假设我有 x 和 y:

x = torch.randn(35, 50)
y = torch.randn(35)

如何将每个 y 值连接到 x[0] 以使 x 的形状为 35,51?

我试过了:

for i in y:
    for a in range(x.shape[0]):
        x[a] = torch.cat((x[a],i),0)

仍然出现形状错误。有什么聪明的方法吗?

1 个答案:

答案 0 :(得分:1)

这应该有效:

reg delete HKLM\SYSTEM\CurrentControlSet\Services\WAS\Parameters /v GenerateKeys /f
net start w3svc
net stop apphostsvc
net start apphostsvc

输出:

z = torch.cat([x,y.reshape(-1,1)], axis=1)
print(z.shape)