tensorflow float32 十进制精度 [英] tensorflow float32 decimal precision

查看:45
本文介绍了tensorflow float32 十进制精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试 Tensorflow intro 时,我遇到了以下代码

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]))

输出

-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?

推荐答案

这里是一个很好的资源来回答这个问题题.解释该网页上的第一段:

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

TensorFlow 没有坏,它在做浮点运算.计算机本身只能存储整数,因此它们需要某种表示十进制数的方法.这种表示带有一定程度的不准确.这就是为什么通常 .3 == .30000001.

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.

这篇关于tensorflow float32 十进制精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆