tf.math.greater 大于运算

介绍

比较函数,大于某个值

常用别名

  • tf.greater

语法

  1. tf.math.greater(
  2. x,
  3. y,
  4. name=None
  5. )
参数
  • x:tensor,必须是类型之一:float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
  • y:tensor,类型与x相同
返回值

布尔类型的tensor

例子

  1. import tensorflow as tf
  2. tens=tf.constant([1,2,3,4,5])
  3. res=tf.greater(tens,3)
  4. print(res)

执行结果:

  1. tf.Tensor([False False False True True], shape=(5,), dtype=bool)

通过 tf.boolean_mask 进行布尔索引

  1. print(tf.boolean_mask(tens,res))

执行结果:

  1. tf.Tensor([4 5], shape=(2,), dtype=int32)

原文出处:http://malaoshi.top/show_1EF5dB3frngj.html