tf.nn.softmax(logits,axis=None,name=None,dim=None)
参数:logits:一个非空的Tensor。必须是下列类型之一:half, float32,float64axis:将在其上执行维度softmax。默认值为-1,表示最后一个维度name:操作的名称(可选)dim:axis的已弃用的别名返回:一个Tensor,与logits具有相同的类型和shape
sample
import tensorflow as tf#tf.enable_eager_execution()tf.compat.v1.enable_eager_execution()ones = tf.ones(shape=[2,3])print(ones)temp1 = tf.nn.softmax(ones,axis=0) # 列print(temp1)temp2 = tf.nn.softmax(ones,axis=1) # 行print(temp2)
output
tf.Tensor([[1. 1. 1.] [1. 1. 1.]], shape=(2, 3), dtype=float32)tf.Tensor([[0.5 0.5 0.5] [0.5 0.5 0.5]], shape=(2, 3), dtype=float32)tf.Tensor([[0.33333334 0.33333334 0.33333334] [0.33333334 0.33333334 0.33333334]], shape=(2, 3), dtype=float32)