1. 表示精度和所需内存
float类型和float64类型是一样的,都需要64个bits,而float32需要32个bits。 精度方面,float类型和float64类型在十进制中可以有16位,而float32类型在十进制中有8位,如下:
>>> x = np.float64(1/3)
>>> x
0.3333333333333333
>>> y = np.float32(x)
>>> y
0.33333334
>>> p = 1000*(1/3)
>>> p
333.3333333333333
>>> q = np.float32(p)
>>> q
333.33334
2.转换
1. ‘float’转’float64’
x
x
x原本是’float’类型的
x = np.float64(x)
经过上面的
x
x
x就变成了’float64’类型
2.’float64’转‘float’
y
y
y原本是’float64’类型的
y = np.float(y)
经过上面的
y
y
y就变成了’float’类型
3. ‘float64’与‘float32’之间的转换
>>> x = np.float64(1/3)
>>> x
0.3333333333333333
>>> y = np.float32(x)
>>> y
0.33333334
>>> z = np.float64(y)
>>> z
0.3333333432674408
3. 当出现如下错误时需要进行类型的转换
ValueError: Unknown label type: 'unknown'
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有