softmax#

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

Apply the softmax function element-wise.

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

  • axis (Optional[int]) – The dimension 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 input array with softmax applied element-wise.

Examples

With ivy.Array input:

>>> x = ivy.array([1.0, 0, 1.0])
>>> y = ivy.softmax(x)
>>> print(y)
ivy.array([0.422, 0.155, 0.422])
>>> x = ivy.array([[1.1, 2.2, 3.3],
...                [4.4, 5.5, 6.6]])
>>> y = ivy.softmax(x, axis = 1)
>>> print(y)
ivy.array([[0.0768, 0.231 , 0.693 ],
           [0.0768, 0.231 , 0.693 ]])
Array.softmax(self, /, *, axis=None, out=None)#

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])
Container.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.softmax. This method simply wraps the function, and so the docstring for ivy.softmax also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container.

  • axis (Optional[Container]) – the axis or axes along which the 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.

Return type:

Container

Returns:

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

Examples

>>> x = ivy.Container(a=ivy.array([1.0, 0]), b=ivy.array([1.3, 0, -1.0]))
>>> y = x.softmax()
>>> print(y)
{
    a: ivy.array([0.7310586, 0.2689414]),
    b: ivy.array([0.72844321, 0.19852395, 0.07303288])
}