一、用法
type() :回数据结构类型(list、dict、numpy.ndarray 等)
dtype() :回数据元素的数据类型(int、float等)
注:
1)由于 list、dict 等可以包含不同的数据类型,因此不可调用dtype()函数
2)np.array 中要求所有元素属于同一数据类型,因此可调用dtype()函数
astype() :改变np.array中所有数据元素的数据类型。
注:能用dtype() 才能用 astype()
二、调用方式
type(a)
a.dtype
b = a.astype(np.int64) #a = a.astype(np.int64)
# 转换类型要赋值
本文详细解析了Python中type()、dtype()和astype()函数的使用方法,介绍了如何查看和转换np.array数据类型的技巧。文章强调了list、dict与np.array在数据类型处理上的区别,以及astype()函数使用的前提条件。
4万+

被折叠的 条评论
为什么被折叠?



