当前位置:网站首页>实例044:矩阵相加
实例044:矩阵相加
2022-08-10 02:01:00 【懒笑翻】
题目:计算两个矩阵相加。
程序分析:创建一个新的矩阵,使用 for 迭代并取出 X 和 Y 矩阵中对应位置的值,相加后放到新矩阵的对应位置中。
一、代码
X = [[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]
Y = [[5, 8, 1],
[6, 7, 3],
[4, 5, 9]]
res = [[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
for i in range(len(res)):
for j in range(len(res[0])):
res[i][j] = X[i][j] + Y[i][j]
print(res)
二、执行结果

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓懒笑翻诚邀您点击下方一起来学习讨论↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
边栏推荐
猜你喜欢
随机推荐
Redis - Basic operations and usage scenarios of String|Hash|List|Set|Zset data types
2020.11.22考试哥德巴赫猜想题解
量化交易策略介绍及应用市值中性化选股
Anchor_generators.py analysis of MMDetection framework
T5:Text-toText Transfer Transformer
[Syntax sugar] About the mapping of category strings to category numeric ids
The 25th day of the special assault version of the sword offer
桌面云组件介绍与安装
Go语言JSON文件的读写操作
官宣出自己的博客了
2022.8.8 Exam Travel Summary
2022.8.8考试清洁工老马(sweeper)题解
ECCV 2022 Oral | CCPL: 一种通用的关联性保留损失函数实现通用风格迁移
GDB之指令基础参数
How Microbes Affect Physical Health
微生物是如何影响身体健康的
数组(一)
2022杭电多校联赛第七场 题解
SQL注入的order by ,limit与宽字节注入
sqlmap dolog外带数据








![[Kali Security Penetration Testing Practice Course] Chapter 8 Web Penetration](/img/5f/907057956658a19306da21c71185ea.png)
