tf.shape()与tf.get_shape()
来源:互联网 发布:双十一淘宝店铺宣言 编辑:程序博客网 时间:2024/05/22 02:28
import tensorflow as tfimport numpy as npx=tf.constant([[1,2,3],[4,5,6]])y =[[1,2,3],[4,5,6]]z= np.arange(24).reshape([2,3,4])sess = tf.Session()x_shape= tf.shape(x)y_shape=tf.shape(y)z_shape=tf.shape(z)print(x_shape)print(y_shape)print(z_shape)print(sess.run(x_shape))print(sess.run(y_shape))print(sess.run(z_shape))
Tensor("Shape_12:0", shape=(2,), dtype=int32)Tensor("Shape_13:0", shape=(2,), dtype=int32)Tensor("Shape_14:0", shape=(3,), dtype=int32)[2 3][2 3][2 3 4]
print(x.get_shape)print(x.get_shape())print(x.get_shape().as_list())#print(sess.run(x.get_shape))
<bound method Tensor.get_shape of <tf.Tensor 'Const_4:0' shape=(2, 3) dtype=int32>>(2, 3)[2, 3]
不能使用sess.run()是因为get_shape()返回的不是tensor,而是元组。
print(y.get_shape())
---------------------------------------------------------------------------AttributeError Traceback (most recent call last)<ipython-input-13-0ef76bb118ce> in <module>()----> 1 print(y.get_shape())AttributeError: 'list' object has no attribute 'get_shape'
print(z.get_shape())
---------------------------------------------------------------------------AttributeError Traceback (most recent call last)<ipython-input-14-07fd160b4a19> in <module>()----> 1 print(z.get_shape())AttributeError: 'numpy.ndarray' object has no attribute 'get_shape'
tf.shape(a)和a.get_shape()比较
相同点:都能得到tensor a 的尺寸
不同点:tf.shape()中a数据类型可以是tensor,list,array。
a.get_shape()中a的数据类型只能是tensor,且返回的是一个元组。
阅读全文
0 0
- tf.shape()与tf.get_shape()
- tf.shape和get_shape()
- tensorflow学习笔记(九):tf.shape()与tensor.get_shape()
- Tensorflow -tf.shape(a)和a.get_shape()
- tf.shape(a)和a.get_shape()
- Tensorflow API 学习(2)-tf.shape(a)和a.get_shape()
- Tf.shape
- tensorflow学习之路(4):tf.shape(xxx) vs. xxx.get_shape()
- tensorflow学习之路(4):tf.shape(xxx) vs. xxx.get_shape()
- TF
- tf
- tf.truncated_normal与tf.random_normal
- tf.InteractiveSession()与tf.Session()
- tf.reduce_mean与tf.reduce_min
- tf中几个shape问题
- tf.Variable()与tf.get_variable()与不同之处
- tf.variable_scope与tf.name_scope不同之处
- TensorFlow 插曲-- tf.placeholder 与 tf.Variable
- AOP的解释
- 如何将xml解析成datatable
- 欢迎使用CSDN-markdown编辑器
- 非金融是作风啊
- 链队列的实现
- tf.shape()与tf.get_shape()
- OpenGL_7:用两个片段着色器和着色器程序分别画2个不同颜色的三角形
- c\c++中比较两个字符串或string对象是否相等
- 大数据,是虚还是实?(为Hadoop预热)
- InternalResourceViewResolver
- CSDN博客的积分计算方法和博客排名规律
- Linux中vim的基本操作以及配置文件更改
- 有关HashTable、HashMap、ConcurrentHashMap
- hdu 5983 Pocket Cube (模拟)