重塑或“串联”沿轴的张量
我有以下形状的张量,t
:torch.size([280,4,768])
。
我想要的是沿第二轴有效地实现串联,导致torch.size([280,3072])
。
例如
:,-1,:]),dim = 1),
但是写这本书的方法更好吗?
如何在不弄乱我的值的情况下沿第二轴重塑?
I have a tensor, t
, of the following shape: torch.Size([280, 4, 768])
.
What I want is to achieve, effectively, concatenation along the second axis, resulting in torch.Size([280, 3072])
.
I know that I can for instance, do:
torch.cat((x[:, -4, :], x[:, -3, :], x[:, -2, :], x[:, -1, :]), dim=1)
but is there a nicer way of writing this?
How do I achieve reshaping along the second axis without messing up my values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以直接应用 >::
Yes you can apply a straight forward
reshape
: