mindspore.ops.Heaviside

class mindspore.ops.Heaviside[source]

Applies the Heaviside step function for input x element-wise.

\[\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}\]

Warning

This is an experimental API that is subject to change or deletion.

Inputs:
  • x (Tensor) - The input tensor. With real number data type.

  • values (Tensor) - The values to use where x is zero. It should be able to broadcast with x have the same dtype as x.

Outputs:

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:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([-1.5, 0., 2.]))
>>> values = Tensor(np.array([0.5]))
>>> heaviside = ops.Heaviside()
>>> y = heaviside(x, values)
>>> print(y)
[0.  0.5 1. ]