PyTorch基本操作

PyTorch基本操作

torch.allclose是一个PyTorch函数,用于检查两个张量是否在某个容忍度范围内近似相等

torch.allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)
input (Tensor) – 第一个输入张量
other (Tensor) – 第二个输入张量
rtol (float) – 相对容忍度
atol (float) – 绝对容忍度
equal_nan (bool) – 如果为True,将视NANs在两个张量中为相等,即使它们处于不同的位置。
返回:
(bool) - 如果两个张量在容忍度范围内是近似的,则返回True,否则返回False。


两个张量a和b被视为近似相等,如果以下条件对所有元素都成立:
|a - b| <= atol + rtol * |b|


import torch
 
a = torch.tensor([1.0, 2.0, 3.0])
b = torch.tensor([1.0, 2.001, 3.0])
 
print(torch.allclose(a, b, rtol=1e-03))  
#True
print(torch.allclose(a, b, rtol=1e-05))

https://www.cnblogs.com/zhongzhaoxie/p/16692999.html

https://www.cnblogs.com/shizyxya/p/zhangyuxue.html

https://blog.csdn.net/pipisorry/article/details/108989515

https://blog.csdn.net/hhhhxxn/article/details/110119567

https://blog.csdn.net/hhhhxxn/category_10609397.html

https://blog.csdn.net/weicao1990/article/details/93204452

posted @ 2024-07-05 14:32  michaelchengjl  阅读(5)  评论(0编辑  收藏  举报