【发布时间】:2017-03-13 07:24:08
【问题描述】:
我正在寻找类似于以下效果的东西:
x.get_shape()
这将给出x 的类型。这个有什么功能吗?
【问题讨论】:
-
您在哪里看到
x.get_shape()返回x的类型?你想知道张量的形状吗?x.get_shape()返回x变量的TensorShape,那你要什么?
标签: python tensorflow
我正在寻找类似于以下效果的东西:
x.get_shape()
这将给出x 的类型。这个有什么功能吗?
【问题讨论】:
x.get_shape() 返回x 的类型?你想知道张量的形状吗? x.get_shape()返回x变量的TensorShape,那你要什么?
标签: python tensorflow
您可以使用get_shape() 来获取张量流变量的形状。
>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.get_shape()
(256, 100)
您可以使用dtype 属性来获取张量流变量的类型。
>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.dtype
<dtype: 'float32_ref'>
您可以使用 dtype 的as_numpy_dtype 属性将tf.dtype 转换为numpy dtype。
>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.dtype.as_numpy_dtype
<class 'numpy.float32'>
【讨论】:
tf.Print() 来打印张量的类型,因为张量的类型在会话运行期间不会改变。 Tensor 类型在您构建图形时确定,因此只需使用print(x.dtype)。
要得到你可以做的类型
x.dtype
【讨论】: