Solved by albanD in post #3 
              
              
                Hi, 
Otherwise, you can linearize the two dimensions into one and then use gather like this: 
import torch

def f(x, idx1, idx2):
    """Compute using for loop
        x: N x B x V
        idx1: N x K matrix where idx1[i, j] is between [0, B)
        idx2: N x K matrix where idx2[i, j] is between [0…