mardi 6 novembre 2018

Tensorflow: what happened when initializing tf.Variable by setting initial_value = tf.random_normal?

I want to make a reusable RANDOM TENSOR x and assign the SAME tensor to the VARIABLE y. That means they should have the same value during Session.run(). But it turns out not that case. So why does NOT y equal x? Please help analysis example snippet below. Thanks.

import tensorflow as tf

x = tf.random_normal([300], seed = 1)
y = tf.Variable(initial_value = x) # expect y get the same random tensor as x

avg = tf.reduce_mean(x - y)

sess = tf.InteractiveSession()
sess.run(y.initializer)

print('avg:', sess.run(avg)) # 0.09999691, I expected it as 0

sess.close()




Aucun commentaire:

Enregistrer un commentaire