1 数据类型
1.1 数值类型
- 标量:单个实数,维度(秩)为0,shape为 [ ]
- 向量:n个实数的有序集合,秩为1,shape为[n]
- 矩阵:n行m列的有序集合,秩为2,shape为[n, m]
- 张量:所有维度数 dim > 2 的数组统称为张量,张量的每个维度也叫做轴(axis)
在tensorflow中,一般也把标量、向量、矩阵也统称为张量,不作区分。
1.1.1数据类型的定义
- 标量
In [3]: tf.constant(1.2)
Out[3]: <tf.Tensor: id=1, shape=(), dtype=float32, numpy=1.2>
id是tensorflow中内部索引对象的编号,shape表示张量的形状,dtype表示张量的数据类型及精度
- 向量
In [4]: tf.constant([1, 2, 3])
Out[4]: <tf.Tensor: id=2, shape=(3,), dtype=int32, numpy=array([1, 2, 3], dtype=int32)>