float32 和 float64 的真正区别 [英] The real difference between float32 and float64

查看:126
本文介绍了float32 和 float64 的真正区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 float16float32 在结果精度方面的实际区别.例如,Numpy 允许您选择所需的数据类型范围(np.float16, np.float32, np.float64).我担心的是,如果我决定使用 float 16 来保留内存并避免可能的溢出,例如与 float32 相比,这会造成最终结果的损失吗?

I want to understand the actual difference between float16 and float32 in terms of the result precision. For instance, Numpy allows you to choose the range of the datatype you want (np.float16, np.float32, np.float64). My concern is that if I decide to go with float 16 to reserve memory and avoid possible overflow, would that create a loss of the final results comparing with float32 for instance?

谢谢

推荐答案

a = np.array([0.123456789121212,2,3], dtype=np.float16)
print("16bit: ", a[0])

a = np.array([0.123456789121212,2,3], dtype=np.float32)
print("32bit: ", a[0])

b = np.array([0.123456789121212121212,2,3], dtype=np.float64)
print("64bit: ", b[0])

  • 16 位:0.1235
  • 32 位:0.12345679
  • 64 位:0.12345678912121212
  • 这篇关于float32 和 float64 的真正区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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