快捷方式

torch.isclose

torch.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) Tensor

返回一個新張量,其布林元素表示 input 的每個元素是否與 other 的對應元素“接近”。接近的定義如下:

inputiotherirtol×otheri+atol\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}

其中 inputother 是有限的。如果 input 和/或 other 是非有限的,它們僅當相等時才被視為接近,當 equal_nan 為 True 時,兩個 NaN 被視為相等。

引數
  • input (Tensor) – 第一個用於比較的張量

  • other (Tensor) – 第二個用於比較的張量

  • rtol (float, 可選) – 相對容差。預設值: 1e-05

  • atol (float, 可選) – 絕對容差。預設值: 1e-08

  • equal_nan (bool, 可選) – 如果為 True,則兩個 NaN 將被視為相等。預設值: False

示例

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

文件

訪問全面的 PyTorch 開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源