张量比较
功能 | 函数代码 |
---|
输出转换为概率 | tf.nn.softmax(x, axis) |
张量是否相等 | tf.equal(a, b)或 tf.math.equal(a,b) |
大于 | tf.math.greater |
小于 | tf.math.less |
大于等于 | tf.math.greater_equal |
小于等于 | tf.math.less_equal |
不等于 | tf.math.not_equal |
𝑎 = nan | tf.math.is_nan |
输出转换为概率
- tf.nn.softmax(x, axis)
- 返回值为
e
x
j
∑
e
x
i
\cfrac{e^ {x_j} }{\sum e^{x_i}}
∑exiexj
- 同一维度上返回值相加为1
示例:
import tensorflow as tf
x = tf.random.normal([5, 2])
y = tf.random.normal([5, 2])
print(x)
print(y)
out = tf.nn.softmax(x,axis=1)
print(out)
print(tf.equal(x, y))
out:
tf.Tensor(
[[-0.96936876 -0.1097572 ]
[-0.4655563 -0.78135467]
[ 0.62267804 -0.8209118 ]
[ 0.4610075 -1.0729823 ]
[ 0.7761483 -0.01354323]], shape=(5, 2), dtype=float32)
tf.Tensor(
[[-1.2909575 -0.4212122 ]
[ 0.5929227 2.00815 ]
[ 1.9489411 0.17461295]
[ 0.6395485 0.14574438]
[ 0.63212156 -0.18796994]], shape=(5, 2), dtype=float32)
tf.Tensor(
[[0.2974205 0.7025795 ]
[0.57829994 0.42170003]
[0.80900997 0.19099005]
[0.82258934 0.17741069]
[0.6877651 0.3122349 ]], shape=(5, 2), dtype=float32)
tf.Tensor(
[[False False]
[False False]
[False False]
[False False]
[False False]], shape=(5, 2), dtype=bool)