当前位置:网站首页>实例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)
二、执行结果
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓懒笑翻诚邀您点击下方一起来学习讨论↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
边栏推荐
- 高压之下,必有懦夫
- Introduction and application of quantitative trading strategies
- 月薪35K,靠八股文就能做到的事,你居然不知道
- 2022.8.9 Exam Cube Sum--1100 Question Solutions
- The 25th day of the special assault version of the sword offer
- 官宣出自己的博客啦
- 2022年8月8日-2022年8月15日,ue4视频教程+插件源码()
- FusionConpute虚拟机的发放与管理
- 2022.8.9考试排列变换--1200题解
- Golang nil的妙用
猜你喜欢
随机推荐
Unity3D创建道路插件EasyRoads的使用
Golang nil的妙用
2022.8.9考试游记总结
2022.8.8考试清洁工老马(sweeper)题解
数据库治理利器:动态读写分离
In automated testing, test data is separated from scripts and parameterized methods
ArcGIS Advanced (1) - Install ArcGIS Enterprise and create an sde library
P1564 Worship
小菜鸟河北联通上岗培训随笔
Janus实际生产案例
深度学习(五) CNN卷积神经网络
P1564 膜拜
翻译工具-翻译工具下载批量自动一键翻译免费
LeetCode每日两题02:两数之和 II - 输入有序数组 (均1200道)
.Net面试经验总结
[语法糖] 关于类别字符串到类别数字id的映射
《GB39707-2020》PDF下载
高压之下,必有懦夫
2022.8.9 Exam arrangement and transformation--1200 questions solution
OpenCV图像处理学习四,像素的读写操作和图像反差函数操作