numpy矩阵相关计算


import numpy as np

a = np.matrix([ [1, 2, 3, 4],

[5, 5, 6, 8],

[7, 9, 9, 1],

[4, 6, 7, 1]

])

#矩阵加减法:

e = a + a

#or

e = a - a

#矩阵乘法:

b = a * a#not matrix multiplication!

#or

c = np.dot(a, a)#matrix multiplication

#or

d = a

np.dot(a, a, d)#matrix multiplication

#转置矩阵(transpose)

g = a.transpose()

#or

h = a.T#not matrix transpose!

#逆矩阵(inverse)

#The inverse of a matrixAis the matrixBsuch thatAB=IwhereIis the identity matrix consisting of ones down the main diagonal. Usually Bis denotedB=A-1.

#In SciPy, the matrix inverse of the Numpy array,A, is obtained usinglinalg.inv(A), or usingA.I

f = np.linalg.inv(a)

#or

f = a ** (-1)

#or

f = a.I

#行列式(determinant)

j = np.linalg.det(a)

#伴随矩阵(adjoint)

#(need more test)

m = np.dot(np.linalg.det(a), np.linalg.inv(a))# A-1= A''/ |A|  ==>A''=A-1|A|

#矩阵范数(matrix norms)

k = np.linalg.norms(a)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容