tf.keras.ops.heaviside

Heaviside step function.

The Heaviside step function is defined as: heaviside(x1, x2) = 0 if x1 < 0, 1 if x1 > 0, x2 if x1 == 0

x1 A tensor input.
x2 A scalar or tensor, the value to return when x1 == 0.

A tensor with a shape determined by broadcasting x1 and x2.

Example:

x1 = keras.ops.convert_to_tensor([-2.0, 0.0, 3.0])
x2 = 0.5
keras.ops.heaviside(x1, x2)
array([0. , 0.5, 1. ], dtype=float32)