log_softmax#

ivy.log_softmax(x, /, *, axis=None, out=None)[source]#

Apply the log_softmax function element-wise.

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

  • axis (Optional[int]) – The dimension log_softmax would be performed on. The default is None. (default: None)

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

Return type:

Array

Returns:

ret – The output array with log_softmax applied element-wise to input.

Examples

With ivy.Array input:

>>> x = ivy.array([-1.0, -0.98])
>>> y = ivy.log_softmax(x)
>>> print(y)
ivy.array([-0.703, -0.683])
>>> x = ivy.array([1.0, 2.0, 3.0])
>>> y = ivy.log_softmax(x)
>>> print(y)
ivy.array([-2.41, -1.41, -0.408])

With ivy.NativeArray input:

>>> x = ivy.native_array([1.5, 0.5, 1.0])
>>> y = ivy.log_softmax(x)
>>> print(y)
ivy.array([-0.68, -1.68, -1.18])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([1.5, 0.5, 1.0]))
>>> y = ivy.log_softmax(x)
>>> print(y)
{
    a: ivy.array([-0.68, -1.68, -1.18])
}
>>> x = ivy.Container(a=ivy.array([1.0, 2.0]), b=ivy.array([0.4, -0.2]))
>>> y = ivy.log_softmax(x)
>>> print(y)
{
    a: ivy.array([-1.31, -0.313]),
    b: ivy.array([-0.437, -1.04])
}
Array.log_softmax(self, /, *, axis=None, out=None)#

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 ])
Container.log_softmax(self, /, *, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#

ivy.Container 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 (Container) – input container.

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

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

  • to_apply (bool) – If True, the method will be applied to key_chains, otherwise key_chains (default: True) will be skipped. Default is True.

  • prune_unapplied (bool) – Whether to prune key_chains for which the function was not applied. (default: False) Default is False.

  • map_sequences (bool) – Whether to also map method to sequences (lists, tuples). (default: False) Default is False.

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

Returns:

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

Examples

>>> x = ivy.Container(a=ivy.array([-1.0, -0.98, 2.3]))
>>> y = x.log_softmax()
>>> print(y)
{
    a: ivy.array([-3.37, -3.35, -0.0719])
}
>>> x = ivy.Container(a=ivy.array([1.0, 2.4]), b=ivy.array([-0.2, -1.0]))
>>> y = x.log_softmax()
>>> print(y)
{
    a: ivy.array([-1.62, -0.22]),
    b: ivy.array([-0.371, -1.17])
}