介绍
比较函数,大于某个值
常用别名
- tf.greater
语法
tf.math.greater(
x,
y,
name=None
)
参数
- x:tensor,必须是类型之一:float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
- y:tensor,类型与x相同
返回值
布尔类型的tensor
例子
import tensorflow as tf
tens=tf.constant([1,2,3,4,5])
res=tf.greater(tens,3)
print(res)
执行结果:
tf.Tensor([False False False True True], shape=(5,), dtype=bool)
通过 tf.boolean_mask 进行布尔索引
print(tf.boolean_mask(tens,res))
执行结果:
tf.Tensor([4 5], shape=(2,), dtype=int32)