mindspore.nn.Threshold
- class mindspore.nn.Threshold(threshold, value)[source]
Thresholds each element of the input Tensor.
The formula is defined as follows:
\[\begin{split}y = \begin{cases} x, &\text{ if } x > \text{threshold} \\ \text{value}, &\text{ otherwise } \end{cases}\end{split}\]- Parameters
- Inputs:
input_x (Tensor) - The input of Threshold with data type of float16 or float32.
- Outputs:
Tensor, the same shape and data type as the input.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> from mindspore import Tensor, nn >>> m = nn.Threshold(0.1, 20) >>> inputs = Tensor([0.1, 0.2, 0.3], mindspore.float32) >>> outputs = m(inputs) >>> print(outputs) [ 20.0 0.2 0.3]