Activations#

class ivy.data_classes.array.activations._ArrayWithActivations[source]#

Bases: ABC

_abc_impl = <_abc_data object>#
gelu(*, approximate=False, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • approximate (bool) – whether to use the approximate version of the gelu function. (default: False)

  • 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 gelu activation function applied element-wise.

Examples

>>> x = ivy.array([-1.2, -0.6, 1.5])
>>> y = x.gelu()
>>> print(y)
ivy.array([-0.138, -0.165, 1.4])
leaky_relu(*, alpha=0.2, out=None)[source]#

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])
log_softmax(*, axis=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • axis (Optional[int]) – the axis or axes along which the log_softmax should be computed (default: None)

  • 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 log_softmax activation function applied element-wise.

Examples

>>> x = ivy.array([-1.0, -0.98, 2.3])
>>> y = x.log_softmax()
>>> print(y)
ivy.array([-3.37, -3.35, -0.0719])
>>> x = ivy.array([2.0, 3.4, -4.2])
>>> y = x.log_softmax(x)
ivy.array([-1.62, -0.221, -7.82 ])
mish(*, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

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

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.mish()
>>> print(y)
ivy.array([-0.30340147,  0.        ,  0.86509842])
Return type:

Array

relu(*, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • 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 relu activation function applied element-wise.

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.relu()
>>> print(y)
ivy.array([0., 0., 1.])
sigmoid(*, out=None)[source]#

ivy.Array instance method variant of ivy.sigmoid.

This method simply wraps the function, and so the docstring for ivy.sigmoid also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input array

  • out (Optional[Array]) – optional output array for writing the result to. It must have the same shape (default: None) the input broadcast to default: None

Return type:

Array

Returns:

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

Examples

>>> x = ivy.array([-1., 1., 2.])
>>> y = x.sigmoid()
>>> print(y)
ivy.array([0.269, 0.731, 0.881])
softmax(*, axis=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • axis (Optional[int]) – the axis or axes along which the softmax should be computed (default: None)

  • 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 softmax activation function applied element-wise.

Examples

>>> x = ivy.array([1.0, 0, 1.0])
>>> y = x.softmax()
>>> print(y)
ivy.array([0.422, 0.155, 0.422])
softplus(*, beta=None, threshold=None, out=None)[source]#

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

Parameters:
  • self (Array) – input array.

  • beta (Optional[Union[int, float]]) – the beta parameter of the softplus function. (default: None)

  • threshold (Optional[Union[int, float]]) – the threshold parameter of the softplus function. (default: None)

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

Return type:

Array

Returns:

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

Examples

>>> x = ivy.array([-0.3461, -0.6491])
>>> y = x.softplus()
>>> print(y)
ivy.array([0.535,0.42])
>>> x = ivy.array([-0.3461, -0.6491])
>>> y = x.softplus(beta=0.5)
>>> print(y)
ivy.array([1.22, 1.09])
>>> x = ivy.array([1.31, 2., 2.])
>>> y = x.softplus(threshold=2, out=x)
>>> print(x)
ivy.array([1.55, 2.13, 2.13])