📜  Python – tensorflow.guarantee_const()

📅  最后修改于: 2022-05-13 01:54:31.327000             🧑  作者: Mango

Python – tensorflow.guarantee_const()

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

ensure_const ()用于确保 TensorFlow 运行时输入张量是恒定的。

示例 1:

Python3
# Importing the library
import tensorflow as tf
 
# Initializing the Tensor
x = tf.guarantee_const(5)
 
# Printing the result
print("x: ", x)


Python3
# Importing the library
import tensorflow as tf
 
# Initializing the Tensor
x = tf.Variable(2.0, name ="x")
z = tf.Variable(4.0, name ="z")
 
# Using guarantee_const
y = tf.guarantee_const([x, z])
 
# Printing the result
print("y: ", y)


输出:

x:  tf.Tensor(5, shape=(), dtype=int32)

示例 2:

Python3

# Importing the library
import tensorflow as tf
 
# Initializing the Tensor
x = tf.Variable(2.0, name ="x")
z = tf.Variable(4.0, name ="z")
 
# Using guarantee_const
y = tf.guarantee_const([x, z])
 
# Printing the result
print("y: ", y)

输出:

y:  tf.Tensor([2. 4.], shape=(2, ), dtype=float32)