- TensorFlow 2.0 Quick Start Guide
- Tony Holdroyd
- 103字
- 2021-06-24 16:02:03
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.
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)>
推薦閱讀
- Word 2000、Excel 2000、PowerPoint 2000上機指導與練習
- ABB工業(yè)機器人編程全集
- 嵌入式系統(tǒng)及其開發(fā)應用
- Ansible Quick Start Guide
- AWS:Security Best Practices on AWS
- JBoss ESB Beginner’s Guide
- 基于ARM 32位高速嵌入式微控制器
- Hybrid Cloud for Architects
- 精通數(shù)據(jù)科學算法
- 網(wǎng)絡化分布式系統(tǒng)預測控制
- Apache Superset Quick Start Guide
- Ruby on Rails敏捷開發(fā)最佳實踐
- 網(wǎng)絡脆弱性掃描產(chǎn)品原理及應用
- 電腦故障排除與維護終極技巧金典
- 企業(yè)級Web開發(fā)實戰(zhàn)