[英]IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 3)
I created a random function with the line below我用下面的行创建了一个随机 function
x = torch.randn(4, 3) x = 火炬.randn(4, 3)
and used the transpose function as shown here并使用转置 function 如下所示
torch.transpose(x, 0, 1) torch.transpose(x, 0, 1)
I got the error line below.我得到了下面的错误行。 Who can assist with a solution
谁可以提供解决方案
IndexError Traceback (most recent call last) in () ----> 1 torch.transpose(x, 0, 3) IndexError Traceback (last last call last) in () ----> 1 torch.transpose(x, 0, 3)
IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 3) IndexError:维度超出范围(预计在 [-2, 1] 范围内,但得到 3)
You are trying to transpose x = torch.randn(4, 3), which is 2D.您正在尝试转置二维的 x = torch.randn(4, 3)。 torch.transpose(x, 0, 1) works fine because you swap dimensions 0 and 1. But then, you try to swap dimensions 0 and 3 by doing torch.transpose(x, 0, 3) but your x does not have the 3rd dimension
torch.transpose(x, 0, 1) 工作正常,因为您交换尺寸 0 和 1。但是,您尝试通过执行 torch.transpose(x, 0, 3) 交换尺寸 0 和 3 但您的 x 没有第三维度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.