How to check if two Torch tensors or matrices are equal?
torch.eq(a, b)
eq()
implements the ==
operator comparing each element in a
with b
(if b is a value) or each element in a
with its corresponding element in b
(if b
is a tensor).
Alternative from @deltheil:
torch.all(tens_a.eq(tens_b))
This below solution worked for me:
torch.equal(tensorA, tensorB)
From the documentation:
True
if two tensors have the same size and elements,False
otherwise.