(10)tensorflow张量比较

张量比较

功能函数代码
输出转换为概率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
𝑎 = nantf.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)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小蜗笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值