In python, I can easily index a tensor using another tensor like the example below.

But in C++, when I executed the following code, I got an error.
auto category = torch::tensor({1,2,7,9});
auto sample =  torch::tensor({1,0,2,2});
std::cout<<category[sample]<<std::endl;

What would be the right way to do this? Thanks!