torch.isclose#
- torch.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) Tensor #
返回一个新张量,其中包含布尔元素,表示
input
的每个元素是否与other
的相应元素“接近”。接近度定义为其中
input
和other
是有限的。当input
和/或other
是非有限的时,它们是接近的当且仅当它们相等,此时当equal_nan
为 True 时,NaNs 被视为彼此相等。- 参数
示例
>>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4))) tensor([ True, False, False]) >>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5) tensor([True, True])