如何通过在pytorch中使用除给定索引之外的所有索引来索引张量?

How to index tensor by using all but given indices in pytorch?

假设我有一个张量a

>>> a
tensor([[2, 8],
        [3, 0],
        [4, 2],
        [2, 2],
        [6, 8]])

我还有一个张量 idx 包含我不想 select

的索引
>>> idx
tensor([0, 3, 4])

我应该如何继续 select 除了张量 idx 中存在索引的行之外的所有行? 对于上面的张量 aidx,在 selection 之后,我应该得到输出张量 b 作为

>>> b
tensor([[3, 0],
        [4, 2]])

a[[i for i in range(len(a)) if i not in idx]]