当前位置:网站首页>实例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电子书!↓↓↓↓↓↓
"""边栏推荐
- 【日志框架】
- HBuilderX的下载安装和创建/运行项目
- Google Earth Engine - Calculates the effective width of rivers using publicly available river data
- 【OpenCV】-重映射
- 天地图坐标系转高德坐标系 WGS84转GCJ02
- 【虚拟化生态平台】虚拟化平台搭建
- C 学生管理系统_分析
- [store mall project 01] environment preparation and testing
- 如何通过API接口从淘宝(或天猫店)复制宝贝到拼多多接口代码对接教程
- Linux安装mysql最简单教程(一次成功)
猜你喜欢

typescript50-交叉类型和接口之间的类型说明

typescript48 - type compatibility between functions

typescript53-泛型约束

Installation and configuration of nodejs+npm

ASP.NET 获取数据库的数据并写入到excel表格中
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?

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

计算首屏时间

工程制图平面投影练习

【store商城项目01】环境准备以及测试
随机推荐
简单的线性表的顺序表示实现,以及线性表的链式表示和实现、带头节点的单向链表,C语言简单实现一些基本功能
Promise solves blocking synchronization and turns asynchronous into synchronous
【虚拟户生态平台】虚拟化平台安装时遇到的坑
【无标题】
Observability:你所需要知道的关于 Syslog 的一些知识
工程制图平面投影练习
Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)
Flask Framework Beginner-05-Command Management Manager and Database Use
JS 保姆级贴心,从零教你手写实现一个防抖debounce方法
即席查询——Presto
Quickly build a website with static files
Demand analysis of MES management system in electronic assembly industry
2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
How to find the cause of Fiori Launchpad routing errors by single-step debugging
Installation and configuration of nodejs+npm
静态/动态代理模式
typescript57 - Array generic interface
splice随机添加和删除的写法