说到编程语言python,有一个著名的格言"余生太短,只用python"。如果要分析为什么会存在这么一句格言?python的语法并不简单,有复杂难懂的部分,之所以又这样一句格言,是因为python中有很多强大的模块,就像一个武器库。
![873f0efa5b4f3a177d0106429284cfde.png](https://img-blog.csdnimg.cn/img_convert/873f0efa5b4f3a177d0106429284cfde.png)
Python正式由于这些模块的出现,只要引入这个模块,调用这个模块的集成函数,问题迎刃而解;不需要从头开始,节省了大量的时间。
上一篇文章主要讲述了numpy的数学函数,这节课主要讲一下numpy如何创建矩阵,以及对矩阵的一些运算。
如果要使用numpy模块,首先输入"import numpy as np",引入numpy模块并将它重命名为np。
使用np.array()创建矩阵
![9e924a74a8b815e19b4ea5f3723340a6.png](https://img-blog.csdnimg.cn/img_convert/9e924a74a8b815e19b4ea5f3723340a6.png)
使用函数np.linalg.det()计算矩阵的行列式:
![694ee544c7a0fc23a4cb1f802895be25.png](https://img-blog.csdnimg.cn/img_convert/694ee544c7a0fc23a4cb1f802895be25.png)
使用np.arange()和np.linsapce()创建一维数组
![1d3399fced000e6aa6982a3c3c01d906.png](https://img-blog.csdnimg.cn/img_convert/1d3399fced000e6aa6982a3c3c01d906.png)
使用np.matmul()计算矩阵的乘积:
![d90ae1f972b73c70ade16274d223a6fc.png](https://img-blog.csdnimg.cn/img_convert/d90ae1f972b73c70ade16274d223a6fc.png)
使用该函数np.linalg.eig()求矩阵的特征值和特征向量。
![6acac1a48d999a11cf04a4e9f2027b36.png](https://img-blog.csdnimg.cn/img_convert/6acac1a48d999a11cf04a4e9f2027b36.png)
使用函数np.linalg.inv()求矩阵的逆
![631dcaaf52e8bc34c4c3d47e923b2d33.png](https://img-blog.csdnimg.cn/img_convert/631dcaaf52e8bc34c4c3d47e923b2d33.png)
使用函数A.transpose()实现对矩阵的转置
![ea1409799ad6b6d7cf1b0b3cb23fbfa4.png](https://img-blog.csdnimg.cn/img_convert/ea1409799ad6b6d7cf1b0b3cb23fbfa4.png)
使用函数np.linalg.solve()求线性方程组的解
![2c7d9d74e316605bca422e2fc01fd3a6.png](https://img-blog.csdnimg.cn/img_convert/2c7d9d74e316605bca422e2fc01fd3a6.png)
使用函数np.dot()求数组的内积
![4a3944807e98894b1de5ca17e43cec0e.png](https://img-blog.csdnimg.cn/img_convert/4a3944807e98894b1de5ca17e43cec0e.png)
使用函数np.ones()和np.zeros()创建特殊矩阵
![ed0deb3cd3c07f439ea1fad62cec94dc.png](https://img-blog.csdnimg.cn/img_convert/ed0deb3cd3c07f439ea1fad62cec94dc.png)
使用函数np.identity()创建单位矩阵
![ef75347b6a7a17885f8497d4018f2c0c.png](https://img-blog.csdnimg.cn/img_convert/ef75347b6a7a17885f8497d4018f2c0c.png)
使用函数np.fft.fft()对数据进行一维傅里叶变换
![58b2ae87a5ed98a932c3da5e2fd1b505.png](https://img-blog.csdnimg.cn/img_convert/58b2ae87a5ed98a932c3da5e2fd1b505.png)
![8633619332ccb095e5085400d43eb0cb.png](https://img-blog.csdnimg.cn/img_convert/8633619332ccb095e5085400d43eb0cb.png)
除此之外,numpy还有很多强大的函数和应用,应用于矩阵计算、数据分析等方面。
(该文章为原创,抄袭必究)