r/MLQuestions•
odwjwoh

[tensorflow] I don't understand what this is printing out, it's not what I expect, what's going on with the behavior?

My code is a few short lines:

with tf.Session() as sess:
    throw_1 = tf.random_uniform([10, 3], minval=1, maxval=7, dtype=tf.int32)
    throw_2 = tf.random_uniform([10, 3], minval=1, maxval=7, dtype=tf.int32)
    print(throw_1.eval())
    print(throw_1[0].eval())

the output shows this:

[[4 1 1]
 [4 6 1]
 [5 6 3]
 [2 4 2]
 [1 4 1]
 [1 3 4]
 [3 5 3]
 [2 6 3]
 [1 2 2]
 [2 1 4]]
[5 6 6]

I have no idea where this last output is coming from. I asked it to print out [throw_1[0] and I expect it to print out [4 1 1] with is the first row of the tensor I created. Instead it prints out [5 6 6]. I don't even know where this is coming from, since none of the rows match this, and I called the [0] index so I expect it to print out the first row, but it seems to print out a seemingly randomly generated row of 3. Why is it behaving like this and how do I get the indexes to reference what I expect?

Posted Mar 12, 2018, 9:06 PM UTC

33
Loading comments…