numpy

设定输出数值的小数位数

np.set_printoptions(precision=20)

不使用科学计数法输出

np.set_printoptions(suppress=True)

在数组中添加数组

d1 = np.array([[1,2],[3,4]])
d2 = np.array([[5,6]])
np.append(d1,d2,axis=0)

将矩阵a,b进行拼接

np.concatenate((a,b),axis=0)

比较数组是否相等

a=np.array([[1,2,3],[4,5,6]])
b=np.array([[1,2,5],[4,4,5]])
c=(a==b)
d=c.any()  #只要有一个TRUE,就返回TRUE
e=c.all()   #必须都是True,才返回True,否则返回False

将矩阵a展开为一维数组

a.flatten()

向量[1,2,3]的二范数

a = np.array([1,2,3])
l2 = np.linalg.norm(a,ord=2)

数组a的最大元素

np.max(a)
posted @ 2020-10-29 13:34  Bill_H  阅读(66)  评论(0编辑  收藏  举报