假设我有一个大小为 (4,4,4,4) 的张量,如何制作一个大小为 (4,4,4,5) 的张量,使得新添加的条目为 1s?
即执行以下操作的正确方法是什么?
#given a tensor points of some size
pshape = list(points.size())
pshape[-1] = 1
z = torch.ones(pshape)
return torch.cat((points, z), -1)
据我所知,对于非单一维度没有特殊的方法来做到这一点。
这里有用的是:
#given a tensor points of some size
pshape = list(points.size())
pshape[-1] += 1
z = torch.ones(pshape)
z[..., 0:-1] = points