Python 为什么tensorflow.rank总是返回空值的形状
作为TensorFlow的初学者,我不明白为什么TensorFlow.rank总是返回带有空值的形状? 这就是我正在做的:Python 为什么tensorflow.rank总是返回空值的形状,python,tensorflow,google-colaboratory,Python,Tensorflow,Google Colaboratory,作为TensorFlow的初学者,我不明白为什么TensorFlow.rank总是返回带有空值的形状? 这就是我正在做的: import tensorflow as tf %tensorflow_version 2.x list_2d = [[1,2,3,4], [5,6,7,8], [9,10,11,12] ] tensor_2d = tf.Variable(list_2d) print(tensor_2d.shape) print(tf
import tensorflow as tf
%tensorflow_version 2.x
list_2d = [[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
tensor_2d = tf.Variable(list_2d)
print(tensor_2d.shape)
print(tf.rank(tensor_2d))
并且输出为
(3, 4)
tf.Tensor(2, shape=(), dtype=int32)
所以我的问题是shape=()
来自tf.rank
输出的是什么
我无法从这里得到太多-这是因为tf.rank()
的输出本身就是一个张量。输出不是以整数形式返回秩,而是一个张量,其具有单个int32值,表示给定输入张量的秩。形状()
是输出值的形状,而不是输入张量(单值张量具有形状()
)。返回值表示唯一寻址每个元素所需的索引数(在您的案例2中)。2是一个0维张量,它解释了为什么形状为空。有关更多信息,请参阅文档