短小精悍算例:Python中用astype()函数转换数据类型

把64位浮点数据转换为32位。

import numpy as np
a=np.array([1.0, 2.0, 3.0])
print("a的数据类型:", a.dtype)
b=a.astype('float32')  # 转行数据类型
print("b的数据类型:", b.dtype)

输出结果:
a的数据类型: float64
b的数据类型: float32

猜你喜欢

转载自blog.csdn.net/weixin_39464400/article/details/106205863
今日推荐