python容器数据类型
1、列表:[] 有序的可变容器
2、元组:() 有序的不可变容器
3、集合:{} 无序的、不包含重复元素的容器
4、字典:{} 无序的键 -值对(key - value)容器
python常用函数
input、print、int、float、str、len、range、sorted、sum、
max、min、lower、upper、split 、join 、append 、extend 、insert、remove
、pop、keys、values、items、get
1、数据类型
dt = np.dtype(np.int32)
dt = np.dtype("i4")
student = np.dtype([("name","S20"),("age","i4")])
2、创建Ndarry对象
创建一维数组
元素类型要相同(str>float>int)
arr = np.array([1,2,3,4])
arr = np.array([1,2,3.33,4.4])
创建多维数组
arr = np.array([[1,2,3],[3,5,6],[7,8,9]])
arr = np.array([[1,2,3,4]],ndmin=2) #ndmin=2是二维数据
dtype参数
arr = np.array([[1,2,3,4]],dtype=np.float32) #浮点数
arr = np.array([[1,2,3,4]],dtype='f') #浮点数
结构化数据类型
student = np.dtype([("name","S20"),("age","i4"),("marke","f4")])
arr = np.array([("sunck",18,99.999),("Tom",12.232,32)],dtype=student)
enpty()函数
arr = np.empty([3,2],dtype=int) # empty(shape,dtype)
zeros()函数
arr = np.zeros(5,dtype=int)
arr = np.zeros([3,2],dtype=int)
arr = np.zeros([3,2],dtype=[("name","S20"),("age","i4"),("marke","f4")])
full()函数
arr = np.full([3,2],dtype="i4",fill_value=1024) #fill_value参数是填充值
eye()函数
arr = np.eye(10,dtype="i4") #对角线\值是1
arange()函数
arr = np.arange(1,11,2,dtype='i4') #arange(起始值,终止值(不含),步长,数据类型)
frombuffer()函数
a = b"i am a good people"
arr = np.frombuffer(a,dtype="S1",count=15,offset=2) #count长度,offset起始值
fromiter()函数,从可迭代对象中建立ndarry对象
x = [1,2,3,4]#列表
z = iter(x)#可迭代对象
arr = np.fromiter(z,dtype="f")
3、切片和索引
a = np.arange(1,20,1)
b = slice(2,7,2)
arr = a[b]
arr = a[2:7:2]
c = a[5] #将返回与该索引相对应的单个元素
d = a[5:] #表示从该索引开始以后的所有项都将被提取