参考链接: equal(other) → bool
参考链接: torch.equal(input, other) → bool
函数说明:
比较两个张量的形状和各个元素是否都相等.
代码实验展示:
Microsoft Windows [版本 10.0.18363.1256]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\chenxuqi>
C:\Users\chenxuqi>conda activate ssd4pytorch1_2_0
(ssd4pytorch1_2_0) C:\Users\chenxuqi>python
Python 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>
>>> input = torch.tensor([1, 2])
>>> other = torch.tensor([1, 2])
>>> input
tensor([1, 2])
>>> other
tensor([1, 2])
>>> torch.equal(input, other)
True
>>> other = torch.tensor([1, 3])
>>> input
tensor([1, 2])
>>> other
tensor([1, 3])
>>> torch.equal(input, other)
False
>>>
>>> other = torch.tensor([[1, 2],[1, 2]])
>>> other
tensor([[1, 2],
[1, 2]])
>>> input
tensor([1, 2])
>>> torch.equal(input, other)
False
>>>
>>> other = torch.tensor([[1, 2],[1, 3]])
>>> torch.equal(input, other)
False
>>> other = torch.tensor([[1, 2]])
>>> other
tensor([[1, 2]])
>>> input
tensor([1, 2])
>>> torch.equal(input, other)
False
>>>
>>>