mindspore.ops.ApproximateEqual

class mindspore.ops.ApproximateEqual(*args, **kwargs)[source]

Returns True if abs(x1-x2) is smaller than tolerance element-wise, otherwise False.

Inputs of x1 and x2 comply with the implicit type conversion rules to make the data types consistent. If they have different data types, lower priority data type will be converted to relatively highest priority data type. RuntimeError exception will be thrown when the data type conversion of Parameter is required.

Parameters

tolerance (float) – The maximum deviation that two elements can be considered equal. Default: 1e-05.

Inputs:
  • x1 (Tensor) - A tensor. Must be one of the following types: float32, float16.

  • x2 (Tensor) - A tensor of the same type and shape as ‘x1’.

Outputs:

Tensor, the shape is the same as the shape of ‘x1’, and the data type is bool.

Raises

TypeError – If tolerance is not a float.

Supported Platforms:

Ascend

Examples

>>> x1 = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> x2 = Tensor(np.array([2, 4, 6]), mindspore.float32)
>>> approximate_equal = ops.ApproximateEqual(2.)
>>> output = approximate_equal(x1, x2)
>>> print(output)
[ True  True  False]