mindspore.ops.softmax
- mindspore.ops.softmax(input, axis=-1, *, dtype=None)[source]
Applies the Softmax operation to the input tensor on the specified axis.
Warning
After version 2.9.0, the parameter axis will be renamed to dim, and the default value will change from
-1toNone.Consider a slice along the given axis \(axis\), then for each element \(input_i\), the Softmax function is shown as follows:
\[\text{output}(input_i) = \frac{\exp(input_i)}{\sum_{j = 0}^{N-1}\exp(input_j)},\]where \(N\) is the length of the tensor.
- Parameters:
- Keyword Arguments:
dtype (
mindspore.dtype, optional) – When set, input will be converted to the specified type, dtype, before execution, and dtype of returned Tensor will also be dtype. Default:None.- Returns:
Tensor, with the same type and shape as the input.
- Raises:
TypeError – If axis is not an int.
- Supported Platforms:
AscendGPUCPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> input = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32) >>> output = ops.softmax(input) >>> print(output) [0.01165623 0.03168492 0.08612854 0.23412167 0.6364086 ]