type()、dtype()、astype() 用法

在 python 中,与数据类型相关函数及属性有三个:

名称 作用
type() 返回参数的数据类型
dtype() 返回数组中元素的数据类型
astype() 对数据类型进行转换

实例:

import numpy as np
a = np.arange(5)
type(a)
Out[4]: numpy.ndarray
a[0].dtype
Out[5]: dtype('int32')
a[0].astype(float)
Out[6]: 0.0
posted @ 2020-07-19 14:07  -费费  阅读(2933)  评论(0)    收藏  举报