tanhshrink#
- ivy.tanhshrink(x, /, *, out=None)[source]#
Apply the tanhshrink function element-wise.
- Parameters:
- Return type:
- Returns:
ret – an array containing the tanhshrink activation of each element in
x
.
Examples
With
ivy.Array
input:>>> x = ivy.array([-1.0, 1.0, 2.0]) >>> y = ivy.tanhshrink(x) >>> print(y) ivy.array([-0.23840582, 0.23840582, 1.03597236])
>>> x = ivy.array([-1.0, 1.0, 2.0]) >>> y = x.tanhshrink() >>> print(y) ivy.array([-0.23840582, 0.23840582, 1.03597236])
>>> x = ivy.array([[-1.3, 3.8, 2.1], [1.7, 4.2, -6.6]]) >>> y = ivy.tanhshrink(x) >>> print(y) ivy.array([[-0.43827677, 2.80100036, 1.12954807], [ 0.76459098, 3.20044947, -5.60000372]])
- Array.tanhshrink(self, /, *, out=None)[source]#
ivy.Array instance method variant of ivy.tanhshrink. This method simply wraps the function, and so the docstring for ivy.tanhshrink also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.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
Examples
>>> x = ivy.array([-1., 0., 1.]) >>> y = x.tanhshrink() >>> print(y) ivy.array([-0.23840582, 0. , 0.23840582])
- Container.tanhshrink(self, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.tanhshrink. This method simply wraps the function, and so the docstring for ivy.tanhshrink also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.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 tanhshrink 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.tanhshrink() >>> print(y) { a: ivy.array([0.23840582, -0.36634541]), b: ivy.array([0.02005103, -0.00262468]) }