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

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)>
主站蜘蛛池模板: 图们市| 吉首市| 长汀县| 闵行区| 陆河县| 岢岚县| 讷河市| 双辽市| 呼玛县| 公主岭市| 永仁县| 崇信县| 台北市| 广元市| 射洪县| 霍邱县| 襄汾县| 遵义县| 莱芜市| 娱乐| 安仁县| 寿阳县| 安顺市| 绥化市| 自治县| 怀宁县| 泰顺县| 康马县| 静宁县| 四子王旗| 汽车| 丽水市| 淅川县| 楚雄市| 宜兰市| 长泰县| 威信县| 临汾市| 建德市| 广德县| 桐乡市|