如何使张量维权?

2024-04-20 06:20:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简单的问题要解决

x = torch.randn(400, 400, 32)
y = torch.randn(400, 32, 32)
out=torch.add(x,y)

RuntimeError: The size of tensor a (400) must match the size of tensor b (32) at non-singleton dimension 1

我试着 y=y.repeat(1, x.size(1),1)但不起作用

我知道错误意味着我试图添加的维度不正确。然而,我很难重塑这些张量,使其具有相同的维数

求你了,我需要你的帮助