# threshold#

ivy.threshold(x, /, *, threshold, value, out=None)[source]#

Apply the threshold function element-wise.

Parameters:
• x (`Union`[`Array`, `NativeArray`]) – input array.

• threshold (`float`) – The value to threshold at.

• value (`float`) – The value to replace with.

• out (`Optional`[`Array`], default: `None`) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

`Array`

Returns:

ret – an array containing the threshold activation of each element in `x`.

Examples

With `ivy.Array` input: >>> x = ivy.array([-1.0, 1.0, 2.0]) >>> y = ivy.threshold(x,value=0.0, threshold=1.5) >>> print(y) ivy.array([0., 0., 2.])

```>>> x = ivy.array([-1.0, 1.0, 2.0])
>>> x.threshold(value=0.0, threshold=1.5)
>>> print(y)
ivy.array([0., 0., 2.])
```
```>>> x = ivy.array([[-1.3, 3.8, 2.1], [1.7, 4.2, -6.6]])
>>> y = ivy.threshold(x, value=0.0, threshold=1.5)
>>> print(y)
ivy.array([[0.        , 3.79999995, 2.0999999 ],
[1.70000005, 4.19999981, 0.        ]])
```
Array.threshold(self, /, *, threshold, value, out=None)[source]#

ivy.Array instance method variant of ivy.threshold. This method simply wraps the function, and so the docstring for ivy.threshold also applies to this method with minimal changes.

Parameters:
• self (`Array`) – input array.

• threshold (`Union`[`int`, `float`]) – threshold value for thresholding operation.

• value (`Union`[`int`, `float`]) – value to replace with if thresholding condition is not met.

• out (`Optional`[`Array`], default: `None`) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

`Array`

Returns:

ret – an array with the thresholding function applied element-wise.

Examples

```>>> x = ivy.array([-1., 0., 1.])
>>> y = x.hreshold(threshold=0.5, value=0.0)
>>> print(y)
ivy.array([0.5, 0.5 , 1. ])
```
Container.threshold(self, /, *, threshold, value, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.threshold. This method simply wraps the function, and so the docstring for ivy.threshold also applies to this method with minimal changes.

Parameters:
• self (`Container`) – input container.

• threshold (`Container`) – threshold value for thresholding operation.

• value (`Container`) – value to replace with if thresholding condition is not met.

• key_chains (`Optional`[`Union`[`List`[`str`], `Dict`[`str`, `str`], `Container`]], default: `None`) – The key-chains to apply or not apply the method to.

• to_apply (`Union`[`bool`, `Container`], default: `True`) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped.

• prune_unapplied (`Union`[`bool`, `Container`], default: `False`) – Whether to prune key_chains for which the function was not applied.

• map_sequences (`Union`[`bool`, `Container`], default: `False`) – Whether to also map method to sequences (lists, tuples).

• out (`Optional`[`Container`], default: `None`) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

`Container`

Returns:

ret – a container with the threshold activation unit function applied element-wise.

Examples

```>>> x = ivy.Container(a=ivy.array([1.0, -1.2]), b=ivy.array([0.4, -0.2]))
>>> y = x.threshold(threshold=0.5, value=0.0)
>>> print(y)
{
a: ivy.array([1., 0.]),
b: ivy.array([0., 0.])
}
```