import numpy as np
A = np.array([1,2,3],[4,5,6])
A.reshape((3,-1))
#-1是懒人写法,自动计算
A.reshape((3,2),order="F")
A[1:] #切片
A[:,2] = 1 # 修改
A[0:2,1:3] #提取交叉位置数据
B = np.array([A,A*2])
np.linspace(start = 1,stop = 15,num = 5) #1~15
#result : 1,4.5,8,11.5,15
np.arange(1,15,5)
#result:1,6,11
np.ones(2,3) #全1矩阵
np.zeros(2,3) #全0矩阵
np.eye(3) #对角单位矩阵
np.diag(np.arange(1,15,5))
#result :1 0 0
0 6 0
0 0 11
#diag函数得到函数对角元素
np.random.seed(2) #指定随机数种子
np.random.randn(3,3) #生成随机数(3,3)随机数组
C = np.random.randn(3,3).T #数组转置
D = np.mat(C) # 数组转换为矩阵
D = D.I #矩阵的逆
原文:https://www.cnblogs.com/akoasm/p/15171100.html