Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

when trying Tensorflow intro i came across the following code

w=tf.Variable(.3,tf.float32)
b=tf.Variable(-.3,tf.float32)

while printing this values it gives following output

print(sess.run(w))
print(sess.run(b))
print(sess.run([w]))
print(sess.run([b]))

Output

-0.3
-0.3
[0.30000001]
[-0.30000001]

why while print as array it gives extra floating point precision? Is there any documentation related this topic?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
243 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is a great resource to answer this question. To paraphrase the first paragraph on that web page :

TensorFlow isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, .3 == .30000001.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...