PyTorch torch.equal function
PyTorch torch reference manual
torch.equal is a PyTorch function for checking whether two tensors are equal. It returns True if two tensors have the same shape and elements.
Function definition
torch.equal(input, other)
Usage examples
Example
import
torch
Create two identical tensors
x
=
torch.
tensor
(
[
1
,
2
,
3
]
)
y
=
torch.
tensor
(
[
1
,
2
,
3
]
)
Check whether they are equal
result
=
torch.
equal
(
x
,
y
)
(
result
)
Create different tensors
a
=
torch.
tensor
(
[
1
,
2
,
4
]
)
b
=
torch.
tensor
(
[
1
,
2
,
3
]
)
result2
=
torch.
equal
(
a
,
b
)
(
result2
)
The output is:
True
False