tensorflow创建张量的方法是什么

avatar
作者
筋斗云
阅读量:2

在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]]]) 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!