NumPy函数库基础。

机器学习实战这本书的第一章,下面是这章的代码,添加了些本人的注释,欢迎指正。

In

from numpy import *
random.rand(4,4)
"""
mat()函数将数组转化为矩阵
"""
randMat = mat(random.rand(4,4))
"""
.I操作实现矩阵求逆运算
"""
# randMat.I
invRandMat = randMat.I
"""
执行矩阵乘法,矩阵与逆矩阵相乘
"""
randMat*invRandMat
"""
有误差,得到误差值
"""
myEye = randMat*invRandMat
myEye - eye(4)

OUT

matrix([[  0.00000000e+00,   2.26241858e-17,  -6.05935799e-17,
           1.76115404e-16],
        [ -2.15279060e-17,   2.22044605e-16,  -1.18162824e-16,
           1.35743489e-16],
        [  9.99619619e-19,  -1.22685988e-17,  -2.22044605e-16,
           9.91247488e-17],
        [  1.00142668e-16,   1.50352035e-17,  -3.19207407e-16,
           0.00000000e+00]])