gpt4 book ai didi

python - torch.rot90 的旋转方向

转载 作者:行者123 更新时间:2023-12-05 01:06:47 24 4
gpt4 key购买 nike

在 torch.rot90 的文档中指出

Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.

但是说我们从轴 0 旋转到轴 1,轴 0 是顺时针还是逆时针方向旋转到轴 1? (因为它们都是 90 度旋转,如下图所示)

enter image description here

最佳答案

axis=0 是指向下方的维度,而 axis=1 指向右侧。像这样可视化轴:

---------> axis=1
|
|
|
\/
axis=0

现在,k>0 表示逆时针方向,k<0 表示顺时针方向。

因此,

>>> x = torch.arange(6).view(3, 2)
>>> x
tensor([[0, 1],
[2, 3],
[4, 5]])

>>> torch.rot90(x, 1, [0,1])
tensor([[1, 3, 5],
[0, 2, 4]])

>>> torch.rot90(x, 1, [1,0])
tensor([[4, 2, 0],
[5, 3, 1]])

torch.rot90() 类似于 numpy.rot90()

例如

numpy.rot90(m, k=1, axes=(0, 1))

意思

enter image description here

关于python - torch.rot90 的旋转方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68493579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com