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

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)>
主站蜘蛛池模板: 巴林左旗| 都江堰市| 仲巴县| 沂源县| 会昌县| 宁阳县| 裕民县| 岳普湖县| 甘孜县| 大渡口区| 邳州市| 嘉义市| 油尖旺区| 苍溪县| 太原市| 徐州市| 仙桃市| 田林县| 广德县| 铜鼓县| 怀集县| 连平县| 临安市| 泉州市| 芜湖市| 公主岭市| 玉田县| 衡水市| 花莲县| 乡城县| 色达县| 兴业县| 获嘉县| 额尔古纳市| 修水县| 巴林右旗| 兴仁县| 淮安市| 玉环县| 渝北区| 青阳县|