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 時,NaN 被視為相等。- 引數
示例
>>> 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])