mindspore.ops.softmin
- mindspore.ops.softmin(x, axis=- 1, *, dtype=None)[源代码]
- 在指定轴上对输入Tensor执行Softmin函数做归一化操作。假设指定轴 \(x\) 上有切片,那么每个元素 \(x_i\) 所对应的Softmin函数如下所示: \[\text{output}(x_i) = \frac{\exp(-x_i)}{\sum_{j = 0}^{N-1}\exp(-x_j)},\]- 其中 \(N\) 代表Tensor的长度。 - 参数:
- x (Tensor) - Softmin的输入,其数据类型为float16或float32。其shape为 \((N, *)\) ,其中 \(*\) 为任意数量的额外维度。 
- axis (Union[int, tuple[int]], 可选) - 指定Softmin操作的轴。默认值: - -1。
 
- 关键字参数:
- dtype ( - mindspore.dtype, 可选) - 如果设置此参数,则会在执行之前将 x 转换为指定的类型,返回的Tensor类型也将为指定类型 dtype。默认值:- None。
 
- 返回:
- Tensor,数据类型和shape与 x 相同。 
- 异常:
- TypeError - axis 不是int或者tuple。 
- TypeError - x 的数据类型既不是float16也不是float32。 
- ValueError - axis 是长度小于1的tuple。 
- ValueError - axis 是一个tuple,其元素不全在[-len(x.shape), len(x.shape))范围中。 
 
- 支持平台:
- Ascend- GPU- CPU
 - 样例: - >>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16) >>> output = ops.softmin(x) >>> print(output) [0.2341 0.636 0.0862 0.01165 0.03168 ]