tf.shape函数

tf.shape

1 tf.shape(
2     input,
3     name=None,
4     out_type=tf.int32
5 )

例如:

  • 将矩阵的维度输出为一个维度矩阵
 1 import tensorflow as tf
 2 import numpy as np
 3 
 4 A = np.array([[[1, 1, 1],
 5                [2, 2, 2]],
 6               [[3, 3, 3],
 7                [4, 4, 4]],
 8               [[5, 5, 5],
 9                [6, 6, 6]]])
10 
11 t = tf.shape(A)
12 with tf.Session() as sess:
13     print(sess.run(t))
14 
15 # 输出
16 [3 2 3]

参数

  • input:张量或稀疏张量
  • name:op 的名字,用于tensorboard中
  • out_type:默认为tf.int32

返回值

  • 返回out_type类型的张量

转载https://blog.csdn.net/apengpengpeng/article/details/80579658

原文地址:https://www.cnblogs.com/Carits/p/12872503.html