Reputation: 647
for a Pytorch tensor A
:
A = tensor([1,0,0],
[0,0,0])
is there way I can check whether the number 1 is an element of the tensor A
?
like is there a pytorch function that returns True is 1 is an element of A
, and returns False if 1 is not an element of A
?
Thank you,
Upvotes: 6
Views: 14614
Reputation: 8507
torch.Tensor
implements __contains__
. So, you can just use:
1 in A
This returns True
if the element 1
is in A
, and False
otherwise.
Upvotes: 10