<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/nn.py#L469-L498) |

Hard sigmoid activation function.

#### View aliases


**Main aliases**

[`tf.keras.ops.nn.hard_sigmoid`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/hard_sigmoid)

<br />

    tf.keras.ops.hard_sigmoid(
        x
    )

#### It is defined as:

`0 if x < -2.5`, `1 if x > 2.5`, `(0.2 * x) + 0.5 if -2.5 <= x <= 2.5`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | Input tensor. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor with the same shape as `x`. ||

<br />

#### Example:

    x = np.array([-1., 0., 1.])
    x_hard_sigmoid = keras.ops.hard_sigmoid(x)
    print(x_hard_sigmoid)
    array([0.3, 0.5, 0.7], shape=(3,), dtype=float64)