1
为什么我们在代码1中使用init = tf.global_variables_initializer()而不是在代码2中?Tensor Flow中的global_variables_initializer()
代码1:
import numpy as np
import tensorflow as tf
y_hat = tf.constant(36, name='y_hat')
y = tf.constant(39, name='y')
loss = tf.Variable((y - y_hat)**2, name='loss')
init = tf.global_variables_initializer()
with tf.Session() as session:
session.run(init)
print(session.run(loss))
代码2:
a = tf.constant(2)
b = tf.constant(10)
c = tf.multiply(a,b)
sess = tf.Session()
print(sess.run(c))