分享

numpy计算矩阵的一些函数用法

 Tech-d 2013-11-04
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 matrix A is the matrix B such that AB=I where I is the identity matrix consisting of ones down the main diagonal. Usually B is denoted B=A-1 . 
#In SciPy, the matrix inverse of the Numpy array, A, is obtained using linalg.inv (A) , or using A.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)













    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多