# softmax¶

paddle.sparse.nn.functional. softmax ( x, axis=- 1, name=None ) [源代码]

$softmax_ij = \frac{\exp(x_ij - max_j(x_ij))}{\sum_j(exp(x_ij - max_j(x_ij))}$

## 参数¶

• x (Tensor) - 输入的稀疏 Tensor，可以是 SparseCooTensor 或 SparseCsrTensor，数据类型为 float32、float64。

• axis (int, 可选) - 指定对输入 SparseTensor 计算 softmax 的轴。对于 SparseCsrTensor，仅支持 axis=-1。默认值：-1。

• name (str，可选) - 具体用法请参见 Name，一般无需设置，默认值为 None。

## 代码示例¶

>>> import paddle

>>> print(x)
[[0.        , 0.95717543, 0.43864486, 0.        ],
[0.84765935, 0.45680618, 0.39412445, 0.        ],
[0.59444654, 0.        , 0.78364515, 0.        ]])

>>> csr = x.to_sparse_csr()
>>> print(csr)
crows=[0, 2, 5, 7],
cols=[1, 2, 0, 1, 2, 0, 2],
values=[0.95717543, 0.43864486, 0.84765935, 0.45680618, 0.39412445,
0.59444654, 0.78364515])

>>> print(out)
crows=[0, 2, 5, 7],
cols=[1, 2, 0, 1, 2, 0, 2],
values=[0.62680405, 0.37319586, 0.43255258, 0.29261294, 0.27483448,
0.45284089, 0.54715902])

>>> coo = x.to_sparse_coo(sparse_dim=2)
>>> print(coo)
indices=[[0, 0, 1, 1, 1, 2, 2],
[1, 2, 0, 1, 2, 0, 2]],
values=[0.95717543, 0.43864486, 0.84765935, 0.45680618, 0.39412445,
0.59444654, 0.78364515])