tensorflow 之 tf.shape()

た 入场券 2021-11-16 10:52 424阅读 0赞

运行环境 : python 3.6.0

第三方库 : tensorflow 1.9.0

tf.shape()

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

例如 :

将矩阵的维度输出为一个维度矩阵 :

  1. # -*- encoding: utf-8 -*-
  2. import tensorflow as tf
  3. import numpy as np
  4. A = np.array([
  5. [
  6. [1, 1, 1],
  7. [2, 2, 2]
  8. ],
  9. [
  10. [3, 3, 3],
  11. [4, 4, 4],
  12. ],
  13. [
  14. [5, 5, 5],
  15. [6, 6, 6],
  16. ]
  17. ])
  18. t = tf.shape(A)
  19. with tf.Session() as sess:
  20. print(sess.run(t))
  21. # 输出 :
  22. """
  23. [3 2 3]
  24. """

参数 :

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

返回值:

  • 返回out_type类型的张量

发表评论

表情:
评论列表 (有 0 条评论,424人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Tensorflow入门 前言

    开始 最近在学习深度学习,在github上开了个坑,写一写自己的学习心路历程。希望有志同道合的小伙伴们一起学习。 这里附上[个人网站的地址][Link 1].我写的深度