Table Of Contents
Table Of Contents

softmax

mxnet.ndarray.softmax(data=None, axis=_Null, temperature=_Null, out=None, name=None, **kwargs)

Applies the softmax function.

The resulting array contains elements in the range (0,1) and the elements along the given axis sum up to 1.

\[softmax(\mathbf{z/t})_j = \frac{e^{z_j/t}}{\sum_{k=1}^K e^{z_k/t}}\]

for \(j = 1, ..., K\)

t is the temperature parameter in softmax function. By default, t equals 1.0

Example:

x = [[ 1.  1.  1.]
     [ 1.  1.  1.]]

softmax(x,axis=0) = [[ 0.5  0.5  0.5]
                     [ 0.5  0.5  0.5]]

softmax(x,axis=1) = [[ 0.33333334,  0.33333334,  0.33333334],
                     [ 0.33333334,  0.33333334,  0.33333334]]

Defined in src/operator/nn/softmax.cc:L100

Parameters:
  • data (NDArray) – The input array.
  • axis (int, optional, default='-1') – The axis along which to compute softmax.
  • temperature (double or None, optional, default=None) – Temperature parameter in softmax
  • out (NDArray, optional) – The output NDArray to hold the result.
Returns:

out – The output of this function.

Return type:

NDArray or list of NDArrays