TensorFlow里如何确定张量形状的实例操作?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1127个文字,预计阅读时间需要5分钟。
我们可以使用`tf.shape()`函数来获取某个张量的形状。以下是一个示例代码:
pythonimport tensorflow as tf
x=tf.reshape(tf.range(1000), [10, 10, 10])sess=tf.Session()shape=sess.run(tf.shape(x))print(shape)
输出:[10 10 10]
我们可以在计算图中使用`tf.shape()`来确保张量的形状。
我们可以使用tf.shape()获取某张量的形状张量。
import tensorflow as tf x = tf.reshape(tf.range(1000), [10, 10, 10]) sess = tf.Session() sess.run(tf.shape(x)) Out[1]: array([10, 10, 10])
我们可以使用tf.shape()在计算图中确定改变张量的形状。
high = tf.shape(x)[0] // 2 width = tf.shape(x)[1] * 2 x_reshape = tf.reshape(x, [high, width, -1]) sess.run(tf.shape(x_reshape)) Out: array([ 5, 20, 10])
我们可以使用tf.shape_n()在计算图中得到若干个张量的形状。
本文共计1127个文字,预计阅读时间需要5分钟。
我们可以使用`tf.shape()`函数来获取某个张量的形状。以下是一个示例代码:
pythonimport tensorflow as tf
x=tf.reshape(tf.range(1000), [10, 10, 10])sess=tf.Session()shape=sess.run(tf.shape(x))print(shape)
输出:[10 10 10]
我们可以在计算图中使用`tf.shape()`来确保张量的形状。
我们可以使用tf.shape()获取某张量的形状张量。
import tensorflow as tf x = tf.reshape(tf.range(1000), [10, 10, 10]) sess = tf.Session() sess.run(tf.shape(x)) Out[1]: array([10, 10, 10])
我们可以使用tf.shape()在计算图中确定改变张量的形状。
high = tf.shape(x)[0] // 2 width = tf.shape(x)[1] * 2 x_reshape = tf.reshape(x, [high, width, -1]) sess.run(tf.shape(x_reshape)) Out: array([ 5, 20, 10])
我们可以使用tf.shape_n()在计算图中得到若干个张量的形状。

