数组的数据类型

1.数组的数据类型

bool     int32     int64    str    float32    float64...................................

2.设置数组的数据类型

(1)设置数组的数据类型

import numpy as np
arr=np.array([[1,2,3,4],[2,3,4,5]],dtype=np.float64)
print('arr:',arr)
print('arr数据类型:',arr.dtype)

当创建数组的时候,没有对数组的数据类型进行限制,数据类型是 int32

当添加上 dtype=np.float64 之后,数组的数组类型就发生了变化。

(2)自定义数据类型

import numpy as np
df=np.dtype([("name",np.str_,40),("height",np.float64),("weight",np.float64)])
arr=np.array([("王宝强",165.0,75.0),("黄渤",170.0,80.0),("徐峥",180.0,85.0)],dtype=df)
print('arr:',arr)
print('arr数据类型:',arr.dtype)

猜你喜欢

转载自blog.csdn.net/g_optimistic/article/details/91893346