mindspore.ops.heaviside

mindspore.ops.heaviside(x, values)[source]

Computes the Heaviside step function for each element in input.

\[\begin{split}\text { heaviside }(\text { x, values })=\left\{\begin{array}{ll} 0, & \text { if x }<0 \\ \text { values, } & \text { if x }==0 \\ 1, & \text { if x }>0 \end{array}\right.\end{split}\]
Parameters
  • x (Tensor) – The input tensor. With real number data type.

  • values (Tensor) – The values to use where x is zero. Values can be broadcast with x. ‘x’ should have the same dtype with ‘values’.

Returns

Tensor, has the same type as ‘x’ and ‘values’.

Raises
  • TypeError – If x or values is not Tensor.

  • TypeError – If data type x and values is different.

  • ValueError – If shape of two inputs are not broadcastable.

Supported Platforms:

GPU CPU

Examples

>>> x = Tensor(np.array([-1.5, 0., 2.]))
>>> values = Tensor(np.array([0.5]))
>>> y = ops.heaviside(x, values)
>>> print(y)
[ 0.  0.5 1. ]