前言
学习笔记来自于Andrew Ng,文末附资料。
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
%matplotlib inline
np.random.seed(1)
Exercise----1
=============================
y_hat = tf.constant(36, name='y_hat') #定义y_hat为固定值36
y = tf.constant(39, name='y') #定义y为固定值39
loss = tf.Variable((y-y_hat)**2, name='loss') #为损失函数创建一个变量
init = tf.global_variables_initializer() #运行之后的初始化(ession.run(init)
sess = tf.Session() #损失变量将被初始化并准备计算
sess.run(init) #初始化变量
print(sess.run(loss)) #创建一个session并打印输出
9
占位符是一个对象,它的值只能在稍后指定,要指定占位符的值,可以使