加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

【Python】numpy数组用dtype=float16初始化的坑

发布时间:2020-12-17 01:23:22 所属栏目:Python 来源:网络整理
导读:【Python坑系列】 为了节约空间,使用numpy数组时候采用了float16,结果发现精度远远不达标 默认的floar64是最接近原本浮点数的 a Out[206]: array([ 0.00010002,0.00010002,0.00010002],dtype=float16) a = 0.0001 * np.ones(10,np.float32) a Out[208]: ar

【Python坑系列】

为了节约空间,使用numpy数组时候采用了float16,结果发现精度远远不达标

默认的floar64是最接近原本浮点数的

a
Out[206]:
array([ 0.00010002,0.00010002,0.00010002],dtype=float16)

a = 0.0001 * np.ones(10,np.float32)

a
Out[208]:
array([ 9.99999975e-05,9.99999975e-05,9.99999975e-05],dtype=float32)

a = 0.0001 * np.ones(10,np.float64)

a
Out[210]:
array([ 0.0001,0.0001,0.0001])

a = 0.9999 * np.ones(10,np.float64)

a
Out[212]:
array([ 0.9999,0.9999,0.9999])




(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读