设置数据类型 arr = np.array( [1, 2, 3], dtype = np.float64 ) print(arr.dtype) # 输出float64 # dtype=np.float64也可以用类型代码代替,即 dtype='d' 转换数据类型 int_arr = arr.astype(np.int32) print(int_arr.type) # 输出int32 注:转换数据类型,最好是从精度小的类型转换为精度大的类型,不然可能会发生数据丢失。 ps:图取自天池numpy基础。