mindspore.ops.hardshrink
- mindspore.ops.hardshrink(x, lambd=0.5)[source]
Hard Shrink activation function. Calculates the output according to the input elements.
The formula is defined as follows:
\[\begin{split}\text{HardShrink}(x) = \begin{cases} x, & \text{ if } x > \lambda \\ x, & \text{ if } x < -\lambda \\ 0, & \text{ otherwise } \end{cases}\end{split}\]HShrink Activation Function Graph:
- Parameters
- Returns
Tensor, has the same data type and shape as the input x.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.array([[ 0.5, 1, 2.0], [0.0533,0.0776,-2.1233]]), mindspore.float32) >>> output = ops.hardshrink(x) >>> print(output) [[ 0. 1. 2. ] [ 0. 0. -2.1233]]