如何在pytorch中交换x和y?

发布于 2025-01-16 03:24:09 字数 282 浏览 1 评论 0原文

给定一个输出张量为 100 * 6(xmin,ymin,xmax,ymax,conf,class),如何在 pytorch 中得到一个 100 * 6(ymin,xmin,ymax,xmax,conf,class) 的张量? 例如,给定一个张量,

x = [[1,2,3,4,5,6],
     [7,8,9,10,11,12]], 

期望的结果是

y = [[2,1,4,3,5,6],
     [8,7,10,9,11,12]]

Given a output tensor as 100 * 6(xmin,ymin,xmax,ymax,conf,class),how can I get a tensor as 100 * 6(ymin,xmin,ymax,xmax,conf,class) in pytorch?
For example, given a tensor

x = [[1,2,3,4,5,6],
     [7,8,9,10,11,12]], 

the desired results is

y = [[2,1,4,3,5,6],
     [8,7,10,9,11,12]]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

陌伤ぢ 2025-01-23 03:24:10

我对此不太确定,但尝试 N6.T 或 N6.transpose?

I'm not completely sure about this, but try N6.T or N6.transpose?

轻拂→两袖风尘 2025-01-23 03:24:10

您应该更清楚地指出,以便其他人理解什么是 xy,它可能与轴混淆。但我明白你的意思,你想交换 ymin 和 xmin 位置以及 xmax、ymax 位置。

因此,最简单的方法是创建一个时间张量 tempt_x 并通过切片交换值。

with x = [[1,2,3,4,5,6],[7,8,9,10,11,12]]

>>> tempt_x = x.copy()
>>> x[:,0] = tempt_x[:,1]
>>> x[:,1] = tempt_x[:,0]
>>> x[:,2] = tempt_x[:,3]
>>> x[:,3] = tempt_x[:,2]
>>> x
array([[ 2,  1,  4,  3,  5,  6],
       [ 8,  7, 10,  9, 11, 12]])

You should point clearer for others to understand what is x and y, it can be confused with the axes. But I got your point, you want to swap ymin and xmin position and xmax, ymax position.

Therefore, the easiest way is creating a temporal tensor tempt_x and swap value by slicing.

with x = [[1,2,3,4,5,6],[7,8,9,10,11,12]]

>>> tempt_x = x.copy()
>>> x[:,0] = tempt_x[:,1]
>>> x[:,1] = tempt_x[:,0]
>>> x[:,2] = tempt_x[:,3]
>>> x[:,3] = tempt_x[:,2]
>>> x
array([[ 2,  1,  4,  3,  5,  6],
       [ 8,  7, 10,  9, 11, 12]])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文