当前位置:网站首页>实例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电子书!↓↓↓↓↓↓
"""边栏推荐
猜你喜欢

typescript51-泛型的基本使用

Slipper —— 虚点,最短路

Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment

阿里云技术专家邓青琳:云上跨可用区容灾和异地多活最佳实践

Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)

优秀的测试/开发程序员,是怎样修炼的?步步为营地去执行......

typescript53-泛型约束

esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)

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

typescript55 - generic constraints
随机推荐
简单的线性表的顺序表示实现,以及线性表的链式表示和实现、带头节点的单向链表,C语言简单实现一些基本功能
typescript48 - type compatibility between functions
Array_Sliding window | leecode brushing notes
Variable string
敏捷交付的工程效能治理
typescript50 - type specification between cross types and interfaces
nodejs+express实现数据库mysql的访问,并展示数据到页面上
多线程 之 JUC 学习篇章一 创建多线程的步骤
jmeter跨平台运行csv等文件
esp32发布机器人电池电压到ros2(micro-ros+CoCube)
C 学生管理系统_添加学生
esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)
KunlunBase 1.0 发布了!
谁说程序员不懂浪漫,表白代码来啦~
GNSS【0】- 专题
boot issue
一个注解替换synchronized关键字:分布式场景下实现方法加锁
5.scrapy中间件&分布式爬虫
Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
持续投入商品研发,叮咚买菜赢在了供应链投入上