mindspore.ops.threshold

mindspore.ops.threshold(input, thr, value)[source]

Returns each element of input after thresholding by thr as a Tensor.

The formula is defined as follows:

\[\begin{split}y = \begin{cases} input, &\text{ if } input > \text{thr} \\ \text{value}, &\text{ otherwise } \end{cases}\end{split}\]
Parameters
  • input (Tensor) – The input of threshold with data type of float16 or float32.

  • thr (Union[int, float]) – The value of the threshold.

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

Returns

Tensor, the same shape and data type as the input.

Raises
  • TypeError – If input is not a Tensor.

  • TypeError – If thr is not a float or an int.

  • TypeError – If value is not a float or an int.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> inputs = mindspore.Tensor([0.0, 2, 3], mindspore.float32)
>>> outputs = ops.threshold(inputs, 1, 100)
>>> print(outputs)
[100.   2.   3.]