How Pytorch Tensor get the index of 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?

import torch

x = torch.tensor(3)

list = torch.tensor([1,2,3,4,5])
idx = (list == x).nonzero().flatten()
print (idx.tolist()) # [2]

list = torch.tensor([1,2,3,3,5])
idx = (list == x).nonzero().flatten()
print (idx.tolist()) # [2, 3]

