我们可以使用tf.shape()获取某张量的形状张量。
import tensorflow as tf
x = tf.reshape(tf.range(1000), [10, 10, 10])
sess = tf.Session()
sess.run(tf.shape(x))
Out[1]: array([10, 10, 10])
我们可以使用tf.shape()在计算图中确定改变张量的形状。
high = tf.shape(x)[0] // 2
width = tf.shape(x)[1] * 2
x_reshape = tf.reshape(x, [high, width, -1])