mindspore.mint.nn.Threshold

View Source On AtomGit
class mindspore.mint.nn.Threshold(threshold, value, inplace=False)[source]

Compute the Threshold activation function element-wise.

The Threshold is defined as:

\[\begin{split}y = \begin{cases} x, &\text{ if } x > \text{threshold} \\ \text{value}, &\text{ otherwise } \end{cases}\end{split}\]
Parameters
  • threshold (Union[int, float]) – The value of the threshold.

  • value (Union[int, float]) – The value to replace with when element is less than threshold.

  • inplace (bool, optional) – Whether to apply erasing inplace. Default: False.

Inputs:
  • input (Tensor) - The input tensor.

Outputs:

Tensor.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> inputs = mindspore.tensor([0.0, 2, 3], mindspore.float32)
>>> net = mindspore.mint.nn.Threshold(1, 100)
>>> outputs = net(inputs)
>>> print(outputs)
[100.   2.   3.]