介绍
返回tensor形状
语法
tf.shape(
input,
out_type=tf.dtypes.int32,
name=None
)
参数:
- input:tensor
- out_type:指定输出类型(int32或 int64)。默认为tf.int32(可选)
返回
返回 input 的形状
例子
t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
print(tf.shape(t))
print(tf.shape(t).numpy())
执行结果:
tf.Tensor([2 2 3], shape=(3,), dtype=int32)
[2 2 3]