mindspore.numpy.isclose
- mindspore.numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[源代码]
Returns a boolean tensor where two tensors 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.
说明
For finite values, isclose uses the following equation to test whether two floating point values are equivalent. \(absolute(a - b) <= (atol + rtol * absolute(b))\) On Ascend, input arrays containing inf or NaN are not supported.
- 参数
a (Union[Tensor, list, tuple]) – Input first tensor to compare.
b (Union[Tensor, list, tuple]) – Input second tensor to compare.
rtol (numbers.Number) – The relative tolerance parameter (see Note).
atol (numbers.Number) – The absolute tolerance parameter (see Note).
equal_nan (bool) – Whether to compare
NaN
as equal. If True,NaN
in a will be considered equal toNaN
in b in the output tensor. Default: False.
- 返回
A
bool
tensor of where a and b are equal within the given tolerance.- 异常
TypeError – If inputs have types not specified above.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> a = np.array([0,1,2,float('inf'),float('inf'),float('nan')]) >>> b = np.array([0,1,-2,float('-inf'),float('inf'),float('nan')]) >>> print(np.isclose(a, b)) [ True True False False True False] >>> print(np.isclose(a, b, equal_nan=True)) [ True True False False True True]