- 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)>
推薦閱讀
- Introduction to DevOps with Kubernetes
- 嵌入式系統(tǒng)應(yīng)用
- 錯(cuò)覺:AI 如何通過數(shù)據(jù)挖掘誤導(dǎo)我們
- Learning Apache Spark 2
- 智能工業(yè)報(bào)警系統(tǒng)
- Supervised Machine Learning with Python
- Docker High Performance(Second Edition)
- 大數(shù)據(jù)驅(qū)動的機(jī)械裝備智能運(yùn)維理論及應(yīng)用
- Spatial Analytics with ArcGIS
- Hands-On Dashboard Development with QlikView
- JRuby語言實(shí)戰(zhàn)技術(shù)
- Serverless Design Patterns and Best Practices
- 數(shù)據(jù)清洗
- ARM嵌入式系統(tǒng)開發(fā)完全入門與主流實(shí)踐
- SQL語言與數(shù)據(jù)庫操作技術(shù)大全