0

I do not know why the value keeps changing every time it is calculated.

Here is my code:

import tensorflow as tf
sample_num = 10
radii = tf.random_uniform([sample_num,1],0,1)
norm1 = tf.reduce_max(radii,axis = 0)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
print(sess.run(norm1))
print(sess.run(norm1))
print(sess.run(norm1))

All three print statements give me different values.

norm1.shape

gives me TensorShape([Dimension(1)]), so it looks like norm1 correctly caught the maximum. I changed the sample number to 1 to see whether it keeps changing and it did.

Can anyone help me figure out what the problem is?

E_net4
  • 27,810
  • 13
  • 101
  • 139
Won Jun Son
  • 135
  • 1
  • 6
  • `norm1` is not a TensorFlow variable, it is just the outcome of `reduce_max` on `radii`, which is a tensor bound to a random source of numbers from a uniform distribution. The suggested duplicate shows how you can create a variable that samples the random value source once. – E_net4 Nov 22 '18 at 14:05
  • Thank you!! It did help me a lot. Then, my question is, is norm1 still the maximum among radii? How can I find the maximum in random_uniform tensor? (except making the tensor into np array since I want to easily use GPU). Hmm.. Maybe I can assign the random_uniform tensor to another fixed variable tensor?, Also, if you leave the exact same thing in an answer form, I'll choose that as an answer! Thank you! – Won Jun Son Nov 23 '18 at 09:42
  • Since the uniform distribution has an upper bound, you can be sure that the random values will never exceed this one (in this case, the minimum is 0 and the maximum is 1). The maximum among a batch of random samples in the distribution is not sure to be the upper bound, on the other hand. Since the given duplicate answers the question, you may instead click on the link to accept the target, so that future visitors may find the answers there. – E_net4 Nov 23 '18 at 09:54

0 Answers0