【1.3】Numpy学习-数组类型转换【.astype()】

ar1 = np.arange(10,dtype=float)
print(ar1,ar1.dtype)
# 可以在参数位置设置数组类型

ar2 = ar1.astype(np.int32)
print(ar2,ar2.dtype)
print(ar1,ar1.dtype)

# a.astype():转换数据类型
# 数组类型用np.int32,而不是直接int32

结果如下:

[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] float64
[0 1 2 3 4 5 6 7 8 9] int32
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] float64


猜你喜欢

转载自blog.csdn.net/weixin_30935137/article/details/80822209
今日推荐