在TensorFlow中,可以使用tf.constant()
函数来创建张量。例如:
import tensorflow as tf
# 创建一个标量
scalar = tf.constant(5)
# 创建一个向量
vector = tf.constant([1, 2, 3])
# 创建一个矩阵
matrix = tf.constant([[1, 2], [3, 4]])
# 创建一个三维张量
tensor = tf.constant([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: TensorFlow中的模型评估指标有哪些