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