1

我用下面的行创建了一个随机函数

x = torch.randn(4, 3)

并使用了此处所示的转置功能

torch.transpose(x, 0, 1)

我得到了下面的错误行。谁可以提供解决方案


IndexError                                Traceback (most recent call last)
<ipython-input-19-28494ba2cedc> in <module>()
----> 1 torch.transpose(x, 0, 3)

IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 3)
4

1 回答 1

0

您正在尝试转置二维的 x = torch.randn(4, 3)。torch.transpose(x, 0, 1) 工作正常,因为您交换尺寸 0 和 1。但是,您尝试通过执行 torch.transpose(x, 0, 3) 交换尺寸 0 和 3 但您的 x 没有第三维度

于 2022-02-02T23:42:54.403 回答