我这样定义一个张量:
x = tf.get_variable("x", [100])
但是当我尝试打印张量的形状时:
打印(tf.shape(x))
我得到Tensor("Shape:0", shape=(1,), dtype=int32),为什么输出的结果不应该是shape=(100)
最佳答案
tf.shape(input, name=None)返回一个表示输入形状的一维整数张量。
您正在寻找:返回 x
变量的 TensorShape
的 x.get_shape()
。
更新:由于这个答案,我写了一篇文章来阐明 Tensorflow 中的动态/静态形状:https://pgaleone.eu/tensorflow/2018/07/28/understanding-tensorflow-tensors-shape-static-dynamic/
关于python - tf.shape() 在 tensorflow 中得到错误的形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37085430/