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
Now is better than never

浙公网安备 33010602011771号