当前位置:网站首页>实例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电子书!↓↓↓↓↓↓
"""
边栏推荐
- 有没有jdbc 链接优炫数据库文档及示例?
- Jmeter cross-platform operation CSV files
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- 快速入门EasyX图形编程
- nodejs切换版本使用(不需要卸载重装)
- Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- 【OpenCV】-重映射
- pygame 中的transform模块
- 【虚拟户生态平台】虚拟化平台安装时遇到的坑
猜你喜欢
快速入门EasyX图形编程
企业虚拟偶像产生了实质性的价值效益
优秀的测试/开发程序员,是怎样修炼的?步步为营地去执行......
redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
GraphQL背后处理及执行过程是什么
Web APIs BOM- 操作浏览器:swiper 插件
typescript54 - generic constraints
2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
哎,又跟HR在小群吵了一架!
随机推荐
Use nodejs switch version (no need to uninstall and reinstall)
js中常用的几种遍历处理数据的方法梳理
this巩固训练,从两道执行题加深理解闭包与箭头函数中的this
C 学生管理系统_添加学生
持续投入商品研发,叮咚买菜赢在了供应链投入上
Google Earth Engine - Calculates the effective width of rivers using publicly available river data
The 600MHz band is here, will it be the new golden band?
天地图坐标系转高德坐标系 WGS84转GCJ02
typescript55 - generic constraints
ASP.NET 获取数据库的数据并写入到excel表格中
谁说程序员不懂浪漫,表白代码来啦~
Sky map coordinate system to Gaode coordinate system WGS84 to GCJ02
GNSS[0]- Topic
哎,又跟HR在小群吵了一架!
LeetCode third topic (the Longest Substring Without Repeating Characters) trilogy # 3: two optimization
- heavy OpenCV 】 【 mapping
【OpenCV】-重映射
循环绕过问题
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
哎,又跟HR在小群吵了一架!