tf.math.less_equal 小于等于运算

介绍

比较函数,小于等于某个值

常用别名

  • tf.less_equal

语法

tf.math.less_equal(
    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.less_equal(tens,3)
print(res)

执行结果:

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

通过 tf.boolean_mask 进行布尔索引

print(tf.boolean_mask(tens,res))

执行结果:

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