假设mat = torch.rand((5,7))和我想通过传递索引来获取第一维(这里是7)的值,比如idxs=[0,4,2,3,6]。我现在能做的就是做mat[[0,1,2,3,4],idxs]。我期望mat[:,idxs]能工作,但它没有。第一个选择是唯一的方法,还是有更好的方法?
发布于 2021-02-23 17:12:47
torch.gather就是你要找的东西:
torch.gather(mat, 1, torch.tensor(idxs)[:, None])https://stackoverflow.com/questions/66329802
复制相似问题