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

【store商城项目01】环境准备以及测试

MongoDB数据接入实践

typescript50 - type specification between cross types and interfaces

Demand analysis of MES management system in electronic assembly industry

Web APIs BOM- 操作浏览器:swiper 插件

静态文件快速建站

typescript53-泛型约束

typescript51 - basic use of generics

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

企业虚拟偶像产生了实质性的价值效益
随机推荐
idea中diagram使用
Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)
Analysis: What makes the Nomad Bridge hack unique
【正则表达式】笔记
html select标签赋值数据库查询结果
静态/动态代理模式
Thinkphp commonly used techniques
ASP.NET 获取数据库的数据并写入到excel表格中
IDEA02:配置SQL Server2019数据库
2022年上半年各大厂Android面试题整理及答案解析(持续更新中......)
5. Scrapy middleware & distributed crawler
Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
持续投入商品研发,叮咚买菜赢在了供应链投入上
boot issue
特征值与特征向量
《Greenplum构建实时数据仓库实践》简介
Use nodejs switch version (no need to uninstall and reinstall)
如何用C语言代码实现商品管理系统开发
《The Google File System》新说
flask框架初学-06-对数据库的增删改查