机器学习篇:Python,NumPy函数库基础
Python基础:https://blog.****.net/qq_34374664/article/details/80012978
NumPy函数库基础 (参考自《机器学习实战》)
先打开Pyhton
>>> from numpy import * 引入NumPy函数库所有模块
>>> random.rand(4,4) 随机创建4x4矩阵
>>> randMat=mat(random.rand(4,4)) 赋值语句
>>> randMat.I 矩阵求逆
>>> invRandMat=randMat.I 赋值语句
>>> randMat*invRandMat 矩阵相乘(矩阵乘以它的逆矩阵结果应当是单位矩阵(除了对角线元素是1,4x4矩阵其他元素应该全是0))
>>> myEye=randMat*invRandMat 赋值语句
>>> myEye-eye(4) eye(4)的作用是创建一个4x4大小的单位矩阵
下面是运行结果,另一方面,如果这些函数都能正常运行,说明已经正确安装NumPy函数库,否则,请移步
https://blog.****.net/qq_15020543/article/details/82950509
>>> from numpy import *
>>> random.rand(4,4)
array([[0.52968867, 0.27295897, 0.43328778, 0.15351488],
[0.38746148, 0.96991943, 0.31615279, 0.97758276],
[0.17381753, 0.69937117, 0.36569362, 0.59213545],
[0.63289993, 0.85300831, 0.05252367, 0.33017053]])
>>> randMat=mat(random.rand(4,4))
>>> randMat.I
matrix([[-3.67137963, 5.61616605, -5.24930488, 4.42793174],
[ 0.7807113 , -4.00703711, 2.87491373, -1.06612482],
[ 2.53688143, -0.62544835, 2.97554257, -3.04149837],
[ 1.12031781, -0.34828213, -0.49333309, 0.44188235]])
>>> invRandMat=randMat.I
>>> randMat*invRandMat
matrix([[ 1.00000000e+00, 7.59160956e-17, 5.12264156e-17,
5.29937977e-17],
[ 8.74862671e-17, 1.00000000e+00, 1.59897727e-16,
-1.95691465e-16],
[-4.54604422e-16, 4.92732200e-16, 1.00000000e+00,
1.93028444e-16],
[-5.51365126e-16, 4.39589407e-16, -6.40992479e-16,
1.00000000e+00]])
>>> myEye=randMat*invRandMat
>>> myEye-eye(4)
matrix([[ 0.00000000e+00, 7.59160956e-17, 5.12264156e-17,
5.29937977e-17],
[ 8.74862671e-17, 2.22044605e-16, 1.59897727e-16,
-1.95691465e-16],
[-4.54604422e-16, 4.92732200e-16, -1.11022302e-16,
1.93028444e-16],
[-5.51365126e-16, 4.39589407e-16, -6.40992479e-16,
2.22044605e-16]])
如果在VS2017下面测试,只需要把需要显示的对象使用print函数打印出来