tensorflow定义常量的方法是什么
lewis
2020-05-05
20次阅读
在 TensorFlow 中定义常量可以使用 tf.constant() 函数,示例如下:
import tensorflow as tf
# 定义一个常量
const_tensor = tf.constant(5.0)
# 打印常量的值
with tf.Session() as sess:
print(sess.run(const_tensor))
在上面的示例中,使用 tf.constant(5.0) 定义了一个常量,然后通过 sess.run() 函数获取并打印了这个常量的值。

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。