当前位置:网站首页>numpy.isclose
numpy.isclose
2022-08-01 23:21:00 【Wanderer001】
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]
Returns a boolean array where two arrays are element-wise equal within a tolerance.
The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b.
Warning:The default atol is not appropriate for comparing numbers that are much smaller than one (see Notes).
Parameters:
a, b:array_like
Input arrays to compare.
rtol:float
The relative tolerance parameter (see Notes).
atol:float
The absolute tolerance parameter (see Notes).
equal_nan:bool
Whether to compare NaN’s as equal. If True, NaN’s in a will be considered equal to NaN’s in b in the output array.
Returns
y:array_like
Returns a boolean array of where a and b are equal within the given tolerance. If both a and b are scalars, returns a single boolean value.
See also
Notes
New in version 1.7.0.
For finite values, isclose uses the following equation to test whether two floating point values are equivalent.
absolute(a - b) <= (atol + rtol * absolute(b))
Unlike the built-in math.isclose, the above equation is not symmetric in a and b – it assumes b is the reference value – so that isclose(a, b) might be different from isclose(b, a). Furthermore, the default value of atol is not zero, and is used to determine what small values should be considered close to zero. The default value is appropriate for expected values of order unity: if the expected values are significantly smaller than one, it can result in false positives. atol should be carefully selected for the use case at hand. A zero value for atol will result in False if either a or b is zero.
Examples
>>> np.isclose([1e10,1e-7], [1.00001e10,1e-8])
array([ True, False])
>>> np.isclose([1e10,1e-8], [1.00001e10,1e-9])
array([ True, True])
>>> np.isclose([1e10,1e-8], [1.0001e10,1e-9])
array([False, True])
>>> np.isclose([1.0, np.nan], [1.0, np.nan])
array([ True, False])
>>> np.isclose([1.0, np.nan], [1.0, np.nan], equal_nan=True)
array([ True, True])
>>> np.isclose([1e-8, 1e-7], [0.0, 0.0])
array([ True, False])
>>> np.isclose([1e-100, 1e-7], [0.0, 0.0], atol=0.0)
array([False, False])
>>> np.isclose([1e-10, 1e-10], [1e-20, 0.0])
array([ True, True])
>>> np.isclose([1e-10, 1e-10], [1e-20, 0.999999e-10], atol=0.0)
array([False, True])边栏推荐
猜你喜欢

What is CICD excuse me

从0到1:图文投票小程序设计与研发笔记

Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D 题解

Secondary Vocational Network Security Competition B7 Competition Deployment Process

E - Integer Sequence Fair

伸展树的特性及实现

数据分析04

隔离和降级

y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)

数据增强--学习笔记(图像类,cnn)
随机推荐
Calculate the distance between two points
隔离和降级
Access the selected node in the console
添加大量元素时使用 DocumentFragments
chrome copies the base64 data of an image
C language - branch statement and loop statement
Getting started with IDEA is enough to read this article
美赞臣EDI 940仓库装运订单详解
数据增强--学习笔记(图像类,cnn)
Chapter 19 Tips and Traps: Common Goofs for Novices
sys_kill system call
[C language advanced] file operation (2)
SQL Server(设计数据库--存储过程--触发器)
云原生DevOps环境搭建
加载字体时避免隐藏文本
When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)
Oracle database is set to read-only and read-write
Interpretation of the paper (GSAT) "Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism"
PostgreSQL Basics--Common Commands