Tensorflow常用函数(三)

1 tensorflow比较函数

# 判断每一个数是否大于threshold
greater = tf.greater(x, threshold)
# 判断每一个数是否小于threshold
less = tf.less(x,threshold)
# 判断每一个数是否大于等于threshold
greater_equal=tf.greater_equal(x, threshold)
# 判断每一个数是否小于等于threshold
less_equal=tf.less_equal(x, threshold)
# 判断每一个数是否等于threshold
equal = tf.equal(x, threshold)
# 判断每一个数是否不等于threshold
not_equal=tf.not_equal(x, threshold)

上面的这些比较函数会输出bool类型的tensor,那么就可以配合tf.where来使用

tf.where(
    condition,
    x=None,
    y=None,
    name=None
)

x中为true的元素值不变,false的元素值替换为y中对应位置的值,x,y是同一shape的
栗子

# 将小于等于threshold的值替换为0
greater = tf.greater(x, threshold)
output = tf.where(greater,x,tf.subtract(x,x))
with tf.Session() as sess:
  feed_dict={x:[1,2,3,4,5],threshold:3}
  print(sess.run(output,feed_dict=feed_dict))

output: [0 0 0 4 5]
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值