Solved by colesbury in post #2 
              
              
                You can either use torch::gather or torch::index. torch::index is the implementation for Python indexing (e.g. x[tensor1, tensor2]). 
Here’s how you can do it with gather: 
  auto x = torch::randn({8, 6});
  int64_t idx_data[8] = { 0, 3, 4, 4, 4, 4, 4, 4 };
  auto idx = x.type().toScalarType(torch::…