在 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()
函数获取并打印了这个常量的值。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:java定义常量的方法是什么