isclose#
- ivy.isclose(a, b, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, out=None)[source]#
Return 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. The default atol is not appropriate for comparing numbers that are much smaller than one
- Parameters:
a (
Union
[Array
,NativeArray
]) – First input array.b (
Union
[Array
,NativeArray
]) – Second input array.rtol (
float
, default:1e-05
) – The relative tolerance parameter.atol (
float
, default:1e-08
) – The absolute tolerance parameter.equal_nan (
bool
, default:False
) – 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.out (
Optional
[Array
], default:None
) – Alternate output array in which to place the result. The default is None.
- Return type:
- Returns:
ret – 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.
Examples
>>> ivy.isclose([1e10,1e-7], [1.00001e10,1e-8]) ivy.array([True, False]) >>> ivy.isclose([1.0, ivy.nan], [1.0, ivy.nan], equal_nan=True) ivy.array([True, True]) >>> ivy.isclose([1e-100, 1e-7], [0.0, 0.0], atol=0.0) ivy.array([False, False]) >>> ivy.isclose([1e-10, 1e-10], [1e-20, 0.999999e-10], rtol=0.005, atol=0.0) ivy.array([False, True])
- Array.isclose(self, b, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, out=None)[source]#
ivy.Array instance method variant of ivy.isclose. This method simply wraps the function, and so the docstring for ivy.isclose also applies to this method with minimal changes.
- Parameters:
self (
Array
) – First input array.b (
Array
) – Second input array.rtol (
float
, default:1e-05
) – The relative tolerance parameter.atol (
float
, default:1e-08
) – The absolute tolerance parameter.equal_nan (
bool
, default:False
) – 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.out (
Optional
[Array
], default:None
) – Alternate output array in which to place the result. The default is None.
- Return type:
Array
- Returns:
ret – A new array holding the result is returned unless out is specified, in which it is returned.
Examples
>>> a = ivy.array([[ 2.1, 3.4, ivy.nan], [ivy.nan, 2.4, 2.1]]) >>> b = ivy.array([[ 2.1, 3.4, ivy.nan], [ivy.nan, 2.4, 2.1]]) >>> a.isclose(b) ivy.array([[True, True, False], [False, True, True]]) >>> a.isclose(b, equal_nan=True) ivy.array([[True, True, True], [True, True, True]]) >>> a=ivy.array([1.0, 2.0]) >>> b=ivy.array([1.0, 2.001]) >>> a.isclose(b, atol=0.0) ivy.array([True, False]) >>> a.isclose(b, rtol=0.01, atol=0.0) ivy.array([True, True])
- Container.isclose(self, b, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.isclose. This method simply wraps the function, and so the docstring for ivy.isclose also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Input container containing first input array.b (
Container
) – Input container containing second input array.rtol (
Union
[float
,Container
], default:1e-05
) – The relative tolerance parameter.atol (
Union
[float
,Container
], default:1e-08
) – The absolute tolerance parameter.equal_nan (
Union
[bool
,Container
], default:False
) – 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.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.out (
Optional
[Container
], default:None
) – Alternate output array in which to place the result. The default is None.
- Return type:
Container
- Returns:
ret – A new array holding the result is returned unless out is specified, in which it is returned.
Examples
With one
ivy.Container
input: >>> x = ivy.Container(a=ivy.array([1.0, ivy.nan]), b=ivy.array([1.0, ivy.nan])) >>> y = ivy.Container(a=ivy.array([1.0, ivy.nan]), b=ivy.array([1.0, ivy.nan])) >>> x.isclose(y) {a: ivy.array([True, False]), b: ivy.array([True, False])
} >>> x.isclose(y, equal_nan=True) {
a: ivy.array([True, True]), b: ivy.array([True, True])
} >>> x = ivy.Container(a=ivy.array([1.0, 2.0]), b=ivy.array([1.0, 2.0])) >>> y = ivy.Container(a=ivy.array([1.0, 2.001]), b=ivy.array([1.0, 2.0])) >>> x.isclose(y, atol=0.0) {
a: ivy.array([True, False]), b: ivy.array([True, True])
} >>> x.isclose(y, rtol=0.01, atol=0.0) {
a: ivy.array([True, True]), b: ivy.array([True, True])
}