【问题标题】:An out of bounds index error when using Pytorch gather使用 Pytorch 收集时出现越界索引错误
【发布时间】:2020-07-10 21:14:40
【问题描述】:

我有Two Tensors

我正在尝试从每一行收集一个,其中列由这些索引指定。所以我想得到:

[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1]

这是我的代码:

self.manDistMat.gather(1, state.unsqueeze(-1)))
self.manDistMat

是 16x16 矩阵,state.unsqueeze(-1) 是另一个矩阵。

当我尝试这个时,我得到了这个错误。

RuntimeError:索引 578437695752307201 超出尺寸 16 的维度 1

我做错了什么?

【问题讨论】:

    标签: deep-learning pytorch


    【解决方案1】:

    我实际上发现这是因为我使用 uint8 张量进行索引。当我用 .long() 切换它时,它起作用了。谁能解释为什么它必须是一个长张量?

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题。它似乎是 pytorch 中的 bug

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-06
        • 2015-03-22
        • 1970-01-01
        • 2021-05-17
        • 2013-10-13
        相关资源
        最近更新 更多