How to check if the number 1
is in torch.tensor([1, 2, 3])
?
import torch
a = torch.arange(3)
b = a + 3
print((a == 1).nonzero().numel() > 0) # 1 is in a -> true
print((b == 1).nonzero().numel() > 0) # 1 is in b -> false
Thank you for your answer, I understand.