tf.shape 返回tensor的形状

介绍

返回tensor形状

语法

  1. tf.shape(
  2. input,
  3. out_type=tf.dtypes.int32,
  4. name=None
  5. )
参数:
  • input:tensor
  • out_type:指定输出类型(int32或 int64)。默认为tf.int32(可选)
返回

返回 input 的形状

例子

  1. t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
  2. print(tf.shape(t))
  3. print(tf.shape(t).numpy())

执行结果:

  1. tf.Tensor([2 2 3], shape=(3,), dtype=int32)
  2. [2 2 3]

原文出处:https://malaoshi.top/show_1EF5bVfx2iZW.html