How Tensor gets the index of specific elements?

I have 2 Tensors named x and list and their definitions are below:

x = torch.tensor(3)
list = torch.tensor([1,2,3,4,5])

Now I want to get the index of element x from list . The expected output is an Integer:

2

How can I do in an easy way?

Hi @Audrey,

You can do this:

(list == x).nonzero()

Thanks for your help, your answer works! :grinning: