当前位置:网站首页>实例038:矩阵对角线之和
实例038:矩阵对角线之和
2022-08-04 01:35:00 【懒笑翻】
题目:求一个3*3矩阵主对角线元素之和。
程序分析: 主对角线上 i 和 j相同
代码:
mat = [[1, 2, 3],
[3, 4, 5],
[4, 5, 6]
]
res = 0
for i in range(len(mat)):
print(i, i, ':', mat[i][i])
res += mat[i][i]
print('主对角线和为:', res)
结果:

"""
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群,扫码下方官方推荐的群即可进入哦
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!↓↓↓↓↓↓
"""边栏推荐
- typescript57 - Array generic interface
- Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)
- Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
- Sky map coordinate system to Gaode coordinate system WGS84 to GCJ02
- 循环绕过问题
- Sticker Spelling - Memory Search / Shape Pressure DP
- HBuilderX的下载安装和创建/运行项目
- Is there any jdbc link to Youxuan database documentation and examples?
- thinkphp 常用技巧
- 谁说程序员不懂浪漫,表白代码来啦~
猜你喜欢

GraphQL背后处理及执行过程是什么

持续投入商品研发,叮咚买菜赢在了供应链投入上

idea中diagram使用

Analysis: What makes the Nomad Bridge hack unique

Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中

2022 中国算力大会发布“创新先锋”优秀成果

【虚拟户生态平台】虚拟化平台安装时遇到的坑

jmeter跨平台运行csv等文件

Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg

js中常用的几种遍历处理数据的方法梳理
随机推荐
Flask框架初学-05-命令管理Manager及数据库的使用
Slipper —— 虚点,最短路
【虚拟户生态平台】虚拟化平台安装时遇到的坑
typescript57 - Array generic interface
贴纸拼词 —— 记忆化搜索 / 状压DP
boot issue
【虚拟化生态平台】虚拟化平台esxi挂载USB硬盘
观察者模式
JS 保姆级贴心,从零教你手写实现一个防抖debounce方法
持续投入商品研发,叮咚买菜赢在了供应链投入上
Vant3 - click on the corresponding name name to jump to the next page corresponding to the location of the name of the TAB bar
2022 中国算力大会发布“创新先锋”优秀成果
网络带宽监控,带宽监控工具哪个好
企业虚拟偶像产生了实质性的价值效益
字符串的排列
谁说程序员不懂浪漫,表白代码来啦~
Promise 解决阻塞式同步,将异步变为同步
typescript52 - simplify generic function calls
静态文件快速建站
Analysis: What makes the Nomad Bridge hack unique