重塑或“串联”沿轴的张量

发布于 2025-02-03 03:48:43 字数 222 浏览 2 评论 0原文

我有以下形状的张量,ttorch.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没结果 2025-02-10 03:48:43

是的,您可以直接应用 >::

>>> x.reshape(len(x), -1)

Yes you can apply a straight forward reshape:

>>> x.reshape(len(x), -1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文