leaky_relu#
- ivy.leaky_relu(x, /, *, alpha=0.2, out=None)[source]#
Apply the leaky rectified linear unit function element-wise.
- Parameters:
- Return type:
- Returns:
ret – The input array with leaky relu applied element-wise.
Examples
With
ivy.Array
input:>>> x = ivy.array([0.39, -0.85]) >>> y = ivy.leaky_relu(x) >>> print(y) ivy.array([ 0.39, -0.17])
>>> x = ivy.array([1.5, 0.7, -2.4]) >>> y = ivy.zeros(3) >>> ivy.leaky_relu(x, out=y) >>> print(y) ivy.array([ 1.5 , 0.7 , -0.48])
>>> x = ivy.array([[1.1, 2.2, 3.3], ... [-4.4, -5.5, -6.6]]) >>> ivy.leaky_relu(x, out=x) >>> print(x) ivy.array([[ 1.1 , 2.2 , 3.3 ], [-0.88, -1.1 , -1.32]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0.0, -1.2]), b=ivy.array([0.4, -0.2])) >>> x = ivy.leaky_relu(x, out=x) >>> print(x) { a: ivy.array([0., -0.24000001]), b: ivy.array([0.40000001, -0.04]) }
- Array.leaky_relu(self, /, *, alpha=0.2, out=None)#
ivy.Array instance method variant of ivy.leaky_relu. This method simply wraps the function, and so the docstring for ivy.leaky_relu also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.alpha (
float
) – the slope of the negative section. (default:0.2
)out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – an array with the leaky relu activation function applied element-wise.
Examples
>>> x = ivy.array([0.39, -0.85]) >>> y = x.leaky_relu() >>> print(y) ivy.array([ 0.39, -0.17])
- Container.leaky_relu(self, /, *, alpha=0.2, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
ivy.Container instance method variant of ivy.leaky_relu. This method simply wraps the function, and so the docstring for ivy.leaky_relu also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container.alpha (
Container
) – array or scalar specifying the negative slope. (default:0.2
)key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container with the leaky relu unit function applied element-wise.
Examples
>>> x = ivy.Container(a=ivy.array([0.39, -0.85]), b=ivy.array([1., -0.2])) >>> y = x.leaky_relu() >>> print(y) { a: ivy.array([0.38999999, -0.17]), b: ivy.array([1., -0.04]) }