本文参考的博客为 https://blog.csdn.net/u013733326/article/details/79971488 原博客中作者用的是tf1.x版本的,本文用的是tf2.x版本,这里挂一下网友整理的两个版本更新的对比 https://docs.qq.com/sheet/DZkR6cUZpdFJ2bUxS?tab=BB08J2 好嘞,开始正文 1 - 导入TensorFlow库 开始之前,我们先导入一些库 import numpy as np import h5py import matplotlib.pyplot as plt import tensorflow as tf from tensorflow.python.framework import ops import tf_utils import time np.random.seed(1) 我们现在已经导入了相关的库,我们将引导你完成不同的应用,我们现在看一下下面的计算损失的公式: import tensorflow as tf tf.compat.v1.disable_eager_execution() #保证session.run()能够正常运行 y_hat = tf.constant(36, name='y_hat') # Define y_hat constant. Set to 36. y =