megengine.functional.nn.softmax

softmax(inp, axis=None)[source]

Applies a \(\text{softmax}(x)\) function.

See Softmax for more details.

Examples

>>> import numpy as np
>>> x = Tensor(np.arange(-5, 5, dtype=np.float32)).reshape(2,5)
>>> out = F.softmax(x)
>>> out.numpy().round(decimals=4)
array([[0.0117, 0.0317, 0.0861, 0.2341, 0.6364],
       [0.0117, 0.0317, 0.0861, 0.2341, 0.6364]], dtype=float32)
Return type

Tensor