当前位置:网站首页>实例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)
二、执行结果
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓懒笑翻诚邀您点击下方一起来学习讨论↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
边栏推荐
猜你喜欢
随机推荐
2022.8.8 exam sweeps the horse (sweeper) antithesis
xss的DOMPurify过滤框架:一个循环问题以及两个循环问题
Fusion Compute网络虚拟化
2022.8.9考试游记总结
宝塔服务器PHP+mysql网页URL跳转问题
中英文互译在线翻译-在线翻译软件
别再用 offset 和 limit 分页了,性能太差!
2022.8.8考试摄像师老马(photographer)题解
【二叉树-简单】112. 路径总和
免费文档翻译软件电脑版软件
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
2022年立下的flag完成情况
2022.8.8 Exam written in memory (memory)
[Kali Security Penetration Testing Practice Course] Chapter 8 Web Penetration
2022.8.8考试游记总结
Write a drop-down refresh component
In automated testing, test data is separated from scripts and parameterized methods
2022.8.9 Exam arrangement and transformation--1200 questions solution
Difference Between Data Mining and Data Warehousing
GDB之指令基础参数