调用numpy
from numpy import *
生成4*4随机数组:
random.rand(4,4)
Out[7]:
array([[ 0.53488217, 0.91218101, 0.57634862, 0.70327876],
[ 0.00937165, 0.80176848, 0.14116376, 0.51859265],
[ 0.38045972, 0.81033417, 0.89786015, 0.15371208],
[ 0.97045262, 0.13953864, 0.84421718, 0.6366337 ]])
调用mat()可将数组转为矩阵
randMat = mat(random.rand(4,4))
randMat.I #求逆阵
Out[9]:
matrix([[-2.60825774, -0.71613744, 4.28565124, -1.16628481],
[ 1.07329432, 3.5145201 , -3.26335117, 0.63685251],
[-0.99200606, -1.02602625, 1.00672486, 1.46254 ],
[ 2.60117342, 0.04372232, -1.50313885, -0.93836023]])
储存逆矩阵
invRandMat = randMat.I
执行矩阵乘法
invRandMat * randMat
创建4*4单位矩阵:eye(4)