np.array()/np.asarray()
a=list(range(10))
a1=np.array(a)
a2=np.array(a)
b=list(range(10))
b1=np.array(b)
b2=np.array(b)
reshape/resize
https://blog.csdn.net/weixin_38094100/article/details/115110443
reshape 是浅拷贝,且不支持inplace操作
np.reshape(data,(shape,...))
data.reshape(shape,...)
resize 是深拷贝,既支持inplace操作也支持非inplace操作
data.resize(shape,...)
np.resize(shape,...)
np.append()/np.concatnate()/np.insert()
np.concatnate() 必须是同维度拼接 np.append() 要注意
np.append(a,data)
a=np.arange(10).reshape(-1,5)
np.insert(a,1,[100,500],axis=1)
data.view()是浅拷贝/data.copy()是深拷贝
生成结构化数据
https://blog.csdn.net/qq_45488242/article/details/105895653
通过字典来创建结构化数组的数据类型
import numpy as np
d1={'names':('name','age','weight'),'formats':('U10','i4','f8')}
array1=np.zeros(4,dtype=d1)
d2=[('name','U10'),('age','i4'),('weight','f8')]
array2=np.zeros(4,dtype=d2)
ndim/itemsize/flags
len(data.shape)=data.ndim
data.itemsize
data.flags
frombuffer()/fromiter()???
http://c.biancheng.net/numpy/array-create.html
高级索引-感觉还要再看
https://blog.csdn.net/m0_50470999/article/details/108450726 https://blog.csdn.net/wangwenzhi276/article/details/53436694
迭代数组
默认列优先迭代 np.nditer(data)
for x in np.nditer(b,[order='C',[op_flags=['readwrite']]]):
print(x,)
for x,y in np.nditer([a,b]):
pass
numpy也能处理字符串数据
np.char.xxx 模块 http://c.biancheng.net/numpy/string-function.html
常见函数
data.flatten()
data.squeeze()
np.squeeze(data)
np.concatnate((a,b))
np.stack([a,b],axis=expand_ndim)
np.hstack([a,b])
np.vstack([a,b])
np.split(a,[index1,index2],axis)
np.hsplit()
np.delete(data,index,axis)
np.argwhere()
np.where()
np.nonzero()
np.extrcat(condiction,data)
np.unique(data)
np.bitwise_and()
np.bitwise_or()
np.invert()
np.degrees()
np.around()
np.floor()
np.ceil()
np.sort()
np.argsort()
np.argmax()
np.argmin()
其他不常见函数
np.rollaxis()
np..swapaxes()
np.broadcast()
np.broadcast_to()
numpy矩阵与线性代数运算
numpy.matlib 库 numpy.linalg 库
|