Tensorflow学习笔记:数据类型
小白心得:如果在百度搜索“数据类型”,可以发现每个人对数据类型都有不同的理解,解释的都是不同的东西,所以下面把所谓数据类型分为了三种:“张量类型”、“节点类型”和“元素类型”
tensorflow版本:1.x
环境:python3.8,tensorflow 2.3。
但是因为使用的教材(《Hands-On Machine Learning with Scikit-Learn and TensorFlow》)是1.x版本,所以在引入tensorflow库时使用了import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
张量类型
首先抛开tensorflow,张量(Tensor)是一个数学概念。只从”数“的角度去理解:
- 0阶张量(标量)有1个数,如 x = 5 x=5 x=5、 y = 10 y=10 y=10 ;
- 1阶张量( n n n维向量)有n个数,如 x ⃗ = ( 1 , 2 ) \vec{x}=(1,2) x=(1,2) (二维)、 y ⃗ = ( 3 , 4 , 5 , 6 , 7 ) \vec{y}=(3,4,5,6,7) y=(3,4,5,6,7) (五维),每一维都是一个标量;
- 2阶张量( m m m行 n n n列的矩阵)有 m × n m\times n m×n个数,如 [ 1 2 3 4 5 6 ] \begin{bmatrix}1&2&3\\4&5&6\end{bmatrix} [1425</