简体   繁体   English

IndexError:维度超出范围(预计在 [-2, 1] 范围内,但得到 3)

[英]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.

相关问题 IndexError:维度超出范围(预期在 [-1, 0] 范围内,但得到 1) - IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) IndexError:尺寸超出范围 - PyTorch 尺寸预计在 [-1, 0] 范围内,但得到 1 - IndexError: Dimension out of range - PyTorch dimension expected to be in range of [-1, 0], but got 1 在 Pytorch 中出现错误:IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) - Getting an Error in Pytorch: IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) IndexError:尺寸超出范围(预计在 [-1, 0] 范围内,但得到 -2)与 torch_geometry - IndexError: Dimension out of range (expected to be in range of [-1, 0], but got -2) with torch_geometry RuntimeError: dimension out of range(预期在 [-1, 0] 范围内,但得到 1) - RuntimeError: dimension out of range (expected to be in range of [-1, 0], but got 1) 维度超出范围(预计在 [-4, 3] 范围内,但得到 64) - Dimension out of range (expected to be in range of [-4, 3], but got 64) pytoch RuntimeError: Dimension out of range (expected to be in range of [-1, 0], but got 1 - pytoch RuntimeError: Dimension out of range (expected to be in range of [-1, 0], but got 1 文件“/model.py”,第 33 行,向前 x_out = torch.cat(x_out, 1) IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) - File "/model.py", line 33, in forward x_out = torch.cat(x_out, 1) IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) InvalidArgumentError:预期维度在 [-1, 1) 范围内,但得到 1 - InvalidArgumentError: Expected dimension in the range [-1, 1) but got 1 IndexError:列表索引超出范围2维列表 - IndexError: list index out of range 2 dimension list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM