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

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)>
主站蜘蛛池模板: 通辽市| 博客| 太湖县| 安徽省| 泸西县| 金寨县| 金秀| 涡阳县| 志丹县| 郸城县| 西和县| 湖州市| 阳信县| 南江县| 会宁县| 嘉义县| 乐陵市| 普格县| 苏州市| 铅山县| 昌平区| 中卫市| 错那县| 隆化县| 河曲县| 和平县| 灵寿县| 西平县| 富锦市| 尼勒克县| 车致| 玉树县| 蕲春县| 车致| 界首市| 新龙县| 顺平县| 灌云县| 长岛县| 鄱阳县| 崇义县|