基于python检查矩阵计算结果
作者:我在吃大西瓜呢 时间:2021-02-22 22:56:32
鉴于最近复习线性代数计算量较大,且1800答案常常忽略一些逆阵、行列式的计算答案,故用Python写出矩阵的简单计算程序,便于检查出错的步骤。
1、行列式
可自行更改阶数
from numpy import *
# 求行列式 ,建议:取小数点前整数
A = array([[3, 1, 1, 1],
[1, 3, 1, 1],
[1, 1, 3, 1],
[1, 1, 1, 3]])
B = linalg.det(A)
print(B)
# 48.000000000000014 正确答案:48
2、矩阵相乘
注意要内标相同
from numpy import *
# 求矩阵相乘
A = array([[1, -1, 1],
[1, 1, 0],
[-1, 0, 1]])
B = array([[3, 0, 0],
[0, 0, 0],
[0, 0, 0]])
# N=AB
N = dot(A, B)
# N=BA,则 N = dot(B, A)
print(N)
# 正确答案:
# [ 3 0 0]
# [ 3 0 0]
# [-3 0 0]
3、逆矩阵
自行判断|A|≠0,这里 A∗ = A−1 · |A|
from numpy import *
# 求逆矩阵 ,建议:取小数点后一位化为分数
A = mat([[1, -1, 1],
[1, 1, 0],
[-1, 0, 1]])
B = A.I
print(B)
# [ 0.33333333 0.33333333 -0.33333333]
# [-0.33333333 0.66666667 0.33333333]
# [ 0.33333333 0.33333333 0.66666667]
# 0.333≈ 1/3 ,0.667≈ 2/3
来源:https://www.cnblogs.com/wangzheming35/p/12912170.html
标签:python,检查,矩阵,结果
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python提取照片坐标信息的实例代码
2023-06-01 16:37:10
Python图片处理模块PIL操作方法(pillow)
2021-11-11 18:19:59
numpy中的随机打乱数据方法np.random.shuffle解读
2023-05-19 08:26:53
思考关于搜索框的设计
2008-12-09 18:17:00
![](https://img.aspxhome.com/file/UploadPic/200812/9/techcrunch2-67.jpg)
Javascript fso操作文件
2008-07-30 12:51:00
python 给图像添加透明度(alpha通道)
2021-05-04 04:57:22
![](https://img.aspxhome.com/file/2023/3/98983_0s.jpg)
MySQL6.0新增特性
2010-03-25 10:08:00
python实现从ftp服务器下载文件的方法
2023-08-02 20:50:54
Python简单删除列表中相同元素的方法示例
2021-10-21 11:25:18
Python实现的石头剪子布代码分享
2023-04-11 09:14:58
Pytorch训练过程出现nan的解决方式
2021-04-21 08:12:08
![](https://img.aspxhome.com/file/2023/4/76824_0s.jpg)
CSS像素图制作攻略
2009-05-19 19:32:00
![](https://img.aspxhome.com/file/UploadPic/20095/19/01-75s.gif)
Python单元测试的9个技巧技巧
2023-03-22 09:58:57
解决Python的str强转int时遇到的问题
2023-02-28 23:03:02
JS分割字符串并放入数组的函数
2023-08-05 15:31:03
如何基于Python爬虫爬取美团酒店信息
2023-10-11 00:12:45
![](https://img.aspxhome.com/file/2023/1/86591_0s.jpg)
基于Python实现一个简易的数据管理系统
2023-08-14 11:49:38
![](https://img.aspxhome.com/file/2023/4/92274_0s.png)
如何防止页面中的敏感信息被提取
2008-05-04 11:59:00
详解Python的三种可变参数
2022-06-18 03:09:27
解决python3 urllib 链接中有中文的问题
2022-10-19 08:43:51