TensorFlow比较判断 tf.less, tf.less_equal, tf.less, tf.equal, tf.not_equal, tf.greater, tf.greater_equal

本文介绍了 TensorFlow 中的 `tf.less` 函数,用于比较两个张量中对应元素的大小。通过实例展示了如何使用 `tf.less` 比较两个浮点数矩阵,并获取布尔结果矩阵。此外,还提到了与 `tf.less_equal`、`tf.equal`、`tf.not_equal`、`tf.greater` 和 `tf.greater_equal` 等函数的相似用法。
摘要由CSDN通过智能技术生成

tf.less
tf.less_equal
tf.less
tf.equal
tf.not_equal
tf.greater
tf.greater_equal
的用法类似, 以下以 tf.less 来举例

函数原型为: tf.less(x, y, name=None)

  • x, y 有相同的shape,并且有相同的数据类型。
  • x, y 中的元素按照对应位置做比较,如果 x 中某元素小于 y 中对应元素,返回 True; 否则,返回 False。
  • tf.less 返回值类型为bool 型,shape 与 x 和 y 相同。
import tensorflow as tf

A_tf = tf.constant([[1, 3, 3],
                    [5, 2, 4]], tf.float32)

B_tf = tf.constant([[3, 2, 1],
                    [2, 4, 5]], tf.float32)

result = tf.less(A_tf, B_tf)

with tf.Session() as sess:
    rs = sess.run(result)
    print(rs)



# 结果为:
# [[ True False False]
#  [False  True  True]]
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Enzo 想砸电脑

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

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

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

打赏作者

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

抵扣说明:

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

余额充值