mindspore.ops.isclose

View Source On Gitee
mindspore.ops.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)[source]

Returns a new Tensor with boolean elements representing if each element of input is “close” to the corresponding element of other. Closeness is defined as:

\[∣input−other∣ ≤ atol + rtol × ∣other∣\]
Parameters
  • input (Tensor) – First Tensor to compare, with data type belongs to float32, float16, int32.

  • other (Tensor) – Second Tensor to compare, with data type belongs to float32, float16, int32.

  • rtol (float, optional) – Relative tolerance. Default: 1e-05 .

  • atol (float, optional) – Absolute tolerance. Default: 1e-08 .

  • equal_nan (bool, optional) – If True, then two NaNs will be considered equal. Default: False .

Returns

A bool Tensor, with the shape as broadcasted result of the input input and other.

Raises
  • TypeError – If either of input and other is not Tensor.

  • TypeError – If either of input and other is not float16, float32 or int32.

  • TypeError – If either of atol and rtol is not float.

  • TypeError – If equal_nan is not bool.

  • TypeError – If the dtype of input is not same as the other.

  • ValueError – If input and other can not be broadcast.

  • ValueError – If either of atol and rtol is less than zero.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input = Tensor(np.array([1.3, 2.1, 3.2, 4.1, 5.1]), mindspore.float16)
>>> other = Tensor(np.array([1.3, 3.3, 2.3, 3.1, 5.1]), mindspore.float16)
>>> output = ops.isclose(input, other)
>>> print(output)
[ True False False False  True]