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])