tf.keras.ops.hard_tanh
Stay organized with collections
Save and categorize content based on your preferences.
Applies the HardTanh function element-wise.
tf.keras.ops.hard_tanh(
x
)
It is defined as:
f(x) = -1 for x < -1, f(x) = x for -1 <= x <= 1, f(x) = 1 for x > 1.
Returns |
Output tensor of same shape as x
where values are clamped between -1 and 1.
|
Example:
x = np.array([-2., -1., 0., 1., 2.])
x_hard_tanh = keras.ops.hard_tanh(x)
print(x_hard_tanh)
array([-1. -1. 0. 1. 1.], shape=(5,), dtype=float64)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[null,null,["Last updated 2026-10-31 UTC."],[],[]]