• 文档 >
  • torch >
  • torch.isclose
快捷键

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 为真时,NaN 被视为相等。

参数:
  • 输入(张量)- 要比较的第一个张量

  • 其他(张量)- 要比较的第二个张量

  • rtol(浮点数,可选)- 相对容差。默认:1e-05

  • atol(浮点数,可选)- 绝对容差。默认:1e-08

  • equal_nan(布尔值,可选)- 如果 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 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源