Pythorch运行时错误:gath中的索引无效

2024-04-23 13:41:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Pythorch的新手,我遇到了这个错误:

x.gather(1, c)

RuntimeError: Invalid index in gather at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:457

以下是关于张量的一些信息:

print(x.size())
print(c.size())
print(type(x))
print(type(c))

torch.Size([128, 2])
torch.Size([128, 1])
<class 'torch.Tensor'>
<class 'torch.Tensor'>

x是浮点值,c是整数,这是问题吗?在


Tags: insizeindextype错误torchclasspythorch
1条回答
网友
1楼 · 发布于 2024-04-23 13:41:06

这仅仅意味着索引张量c有无效的索引。 例如,以下索引张量是有效的:

^{1}$

但是,以下索引张量无效:

^{pr2}$

它给出了你提到的例外情况

RuntimeError: Invalid index in gather

相关问题 更多 >