Check if elements of Tensor are in a List/Array/Tensor

Hi guys,

I have some problems finding the fastest way to obtain the following:

I have a Tensor of indices: like for example
tensor1 = [2,3,4,5,6,7,8]

And I also have a list of indices (or array, or tensor whatever is the easiest for later), like for example:
tensor2 = [3,4,5]

Now what I want to get is a tensor with the same shape as tensor1 with booleans such that each element is True when its in tensor2 and False otherwise. So with the above mentioned example, I would want a tensor like this:
result = [False, True, True, True, False, False, False]

Is there a one-liner in pytorch that can reproduce this functionality? Would be really glad if someone could help me.

Best regards
Marco

A possible solution might be

f = lambda x : x in tensor2
result = list(map(f, tensor1))

However, I suspect that, this approach is not the best practice.

mb this will help (tensor1.view(-1, 1) == tensor1.view(1, -1)).sum(1)