当前位置:网站首页>实例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电子书!↓↓↓↓↓↓
"""边栏推荐
- 【日志框架】
- The idea of the diagram
- The 600MHz band is here, will it be the new golden band?
- 内网穿透-应用
- Flink jdbc connector 源码改造sink之 clickhouse多节点轮询写与性能分析
- typescript54-泛型约束
- Sky map coordinate system to Gaode coordinate system WGS84 to GCJ02
- Promise 解决阻塞式同步,将异步变为同步
- Apache DolphinScheduler actual combat task scheduling platform - a new generation of distributed workflow
- 2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
猜你喜欢

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

计算首屏时间

typescript53-泛型约束

pygame 中的transform模块

js中常用的几种遍历处理数据的方法梳理

MySQL回表指的是什么

Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud

redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)

敏捷交付的工程效能治理

The 600MHz band is here, will it be the new golden band?
随机推荐
Use of lombok annotation @RequiredArgsConstructor
esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)
js中常用的几种遍历处理数据的方法梳理
Promise solves blocking synchronization and turns asynchronous into synchronous
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
Intranet penetration - application
【正则表达式】笔记
typescript57 - Array generic interface
《The Google File System》新说
即席查询——Presto
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
如何用C语言代码实现商品管理系统开发
5.scrapy中间件&分布式爬虫
JS 从零教你手写节流throttle
Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
静态/动态代理模式
nodejs+npm的安装与配置
【无标题】
typescript58 - generic classes
【虚拟化生态平台】虚拟化平台搭建