当前位置:网站首页>实例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电子书!↓↓↓↓↓↓
"""边栏推荐
猜你喜欢
随机推荐
优秀的测试/开发程序员,是怎样修炼的?步步为营地去执行......
Tanabata festival coming, VR panoramic look god assists for you
typescript48 - type compatibility between functions
typescript54-泛型约束
Vant3 - click on the corresponding name name to jump to the next page corresponding to the location of the name of the TAB bar
Promise solves blocking synchronization and turns asynchronous into synchronous
有没有jdbc 链接优炫数据库文档及示例?
2022 中国算力大会发布“创新先锋”优秀成果
谁说程序员不懂浪漫,表白代码来啦~
可变字符串
【Untitled】
Demand analysis of MES management system in electronic assembly industry
贴纸拼词 —— 记忆化搜索 / 状压DP
Quickly build a website with static files
thinkphp 常用技巧
C语言:学生管理系统(链表版)
The 600MHz band is here, will it be the new golden band?
一个注解替换synchronized关键字:分布式场景下实现方法加锁
How to copy baby from Taobao (or Tmall store) through API interface to Pinduoduo interface code docking tutorial
MongoDB数据接入实践









