官术网_书友最值得收藏!

Shaping a tensor

The shape of a tensor is accessed via a property (rather than a function):

t2 = tf.Variable([ [ [0., 1., 2.], [3., 4., 5.] ], [ [6., 7., 8.], [9., 10., 11.] ] ]) # tensor variable
print(t2.shape)

The output will be as follows:

(2, 2, 3)

Tensors may be reshaped and retain the same values, as is often required for constructing neural networks.

Here is an example:

r1 = tf.reshape(t2,[2,6]) # 2 rows 6 cols
r2 = tf.reshape(t2,[1,12]) # 1 rows 12 cols
r1
# <tf.Tensor: id=33, shape=(2, 6), dtype=float32,
numpy= array([[ 0., 1., 2., 3., 4., 5.], [ 6., 7., 8., 9., 10., 11.]], dtype=float32)>

Here is another example:

r2 = tf.reshape(t2,[1,12]) # 1 row 12 columns
r2
# <tf.Tensor: id=36, shape=(1, 12), dtype=float32,
numpy= array([[ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]], dtype=float32)>
主站蜘蛛池模板: 永嘉县| 宁都县| 太白县| 贺兰县| 兴山县| 车险| 仁布县| 上蔡县| 台东县| 都江堰市| 响水县| 札达县| 安岳县| 辽宁省| 祁东县| 会宁县| 五大连池市| 三都| 长岭县| 于都县| 巨鹿县| 宜昌市| 封丘县| 湖南省| 新郑市| 承德市| 怀来县| 碌曲县| 安仁县| 缙云县| 赞皇县| 贵德县| 柯坪县| 榕江县| 东台市| 九寨沟县| 灵宝市| 海伦市| 乌苏市| 射阳县| 郑州市|