一、基本操作
1、tensor和numpy之间的转换
numpy转换为list
使用tolist()方法
numpy转换为tensor
Tensor = tf.convert_to_tensor(numpy类型的数据)
tensor转换为numpy
numpy = tensor.numpy()
2、定义tensor时指定数据类型
tensor = tf.constant(M, dtype = tf.double)
# double就是float64
3、tensorflow2的数据类型转换
4、计算向量均值
注:bitcast和cast有区别
5、通过numpy将行向量转换为列向量
通过tensorflow2来转置,注意申明时的写法
6、张量的合成与分割
7、自动求导
tensorflow2官网介绍自动微分
8、将矩阵转化为向量
二、tensorflow与神经网络
1、tf.keras.layers.Flatten()
2、tf.keras.layers.Dense()
3、tf.keras.layers.Dropout()
4、model.compile()
model.compile()的作用就是为搭建好的神经网络模型设置损失函数loss、优化器optimizer、准确性评价函数metrics
5、model.fit()
6、列表式向量拼接
7、tensorflow2生成随机矩阵
tf.random.normal([1,2])