Python ``tensorflow.math.is_non_decreasing()`` 非递减序列判断函数与实例


发布日期 : 2020-04-09 11:43:52 UTC

访问量: 10 次浏览

Python – tensorflow.math.is\_non\_decreasing()

TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

is\_non\_decreasing()如果x是非递减的,返回true。

语法:
tensorflow.math.is_non_decreasing( x, name)

参数:

  • x:它是一个数字张量。
  • name(可选):它定义了该操作的名称

返回:它返回一个dtype bool的张量。

示例 1:

# importing the library
import tensorflow as tf

# Initializing the input tensor
a = tf.constant([2, 3, 3, 5], dtype = tf.float64)

# Printing the input tensor
print('a: ', a)

# Calculating the result
res = tf.math.is_non_decreasing(a)

# Printing the result
print('Result: ', res)

输出:

a: tf.Tensor([2. 3. 3. 5.], shape=(4, ), dtype=float64)
Result: tf.Tensor(True, shape=(), dtype=bool)

示例 2:

# Importing the library
import tensorflow as tf

# Initializing the input tensor
a = tf.constant([7, 8, 13, 11], dtype = tf.float64)

# Printing the input tensor
print('a: ', a)

# Calculating the result
res = tf.math.is_non_decreasing(a)

# Printing the result
print('Result: ', res)

输出:

a: tf.Tensor([ 7. 8. 13. 11.], shape=(4, ), dtype=float64)
Result: tf.Tensor(False, shape=(), dtype=bool)