mindspore.Tensor.isclose
- Tensor.isclose(x2, rtol=1e-05, atol=1e-08, equal_nan=False)[source]
Returns a boolean Tensor where two Tensors are element-wise equal within a tolerance.
- Parameters
x2 (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 Tensor and x2.
- Raises
TypeError – If either of self Tensor and x2 is not Tensor.
TypeError – If either of self Tensor and x2 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 self Tensor is not same as the x2.
ValueError – If self Tensor and x2 can not be broadcast.
ValueError – If either of atol and rtol is less than zero.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> 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 = input.isclose(other) >>> print(output) [ True False False False True]