我想连接Tensor,不是沿着一个维度,而是通过创建一个新的维度。
例如:
x = torch.randn(2, 3)
x.shape # (2, 3)
torch.cat([x,x,x,x], 0).shape # (8, 3)
# This concats along dim 0, not what I want
torch.cat([x,x,x,x], -1).shape # (2, 10)
# This concats along dim 1, not what I want
torch.cat([x[None, :, :],x[None, :, :],x[None, :, :],x[None, :, :]], 0).shape
# => (4, 2, 3)
# This is what I want, but unwieldy
有更简单的方法吗?
1条答案
按热度按时间5kgi1eie1#
只需使用焊炬。堆栈: