前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【tensorflow】shape与ndim

【tensorflow】shape与ndim

作者头像
JNingWei
发布2020-03-31 11:58:21
1.5K0
发布2020-03-31 11:58:21
举报
文章被收录于专栏:JNing的专栏

获取shape

代码语言:javascript
复制
import tensorflow as tf

tensor = tf.placeholder(dtype=tf.float32, shape=[200, 200, 3])

print('\n=========== get shape ============')
print('tensor                   : ', tensor)
print('tensor.shape             : ', tensor.shape)
print('tensor.get_shape()       : ', tensor.get_shape())

Print:

代码语言:javascript
复制
=========== get shape ============
tensor                   :  Tensor("Placeholder:0", shape=(200, 200, 3), dtype=float32)
tensor.shape             :  (200, 200, 3)
tensor.get_shape()       :  (200, 200, 3)

获取ndim

代码语言:javascript
复制
import tensorflow as tf

tensor = tf.placeholder(dtype=tf.float32, shape=[200, 200, 3])

print('\n=========== get dims ============')
print('tf.shape(tensor)         : ', tf.shape(tensor))
print('tensor.shape.ndims       : ', tensor.shape.ndims)
print('tensor.get_shape().ndims : ', tensor.get_shape().ndims)

Print:

代码语言:javascript
复制
=========== get dims ============
tf.shape(tensor)         :  Tensor("Shape:0", shape=(3,), dtype=int32)
tensor.shape.ndims       :  3
tensor.get_shape().ndims :  3

补充

  • 需要特别注意的是,tf.shape(tensor)返回的其实是ndim,而非标准意义上的shape!
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/03/28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 获取shape
  • 获取ndim
  • 补充
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档