当前位置:网站首页>Instance, 038: the sum of the diagonal matrix
Instance, 038: the sum of the diagonal matrix
2022-08-04 01:43:00 【Lazy laughing】
Title: Find the sum of the main diagonal elements of a 3*3 matrix.
Program Analysis: i and j are the same on the main diagonal
Code:
mat = [[1, 2, 3],[3, 4, 5],[4, 5, 6]]res = 0for i in range(len(mat)):print(i, i, ':', mat[i][i])res += mat[i][i]print('The main diagonal sum is: ', res)Results:

"""Problems encountered during study and no one answered?The editor has created a QQ group for Python learning and communication, and you can enter the officially recommended group by scanning the code below.Looking for like-minded friends to help each other, there are also good video learning tutorials and PDF e-books in the group!↓↓↓↓↓↓"""边栏推荐
猜你喜欢

DDTL:远距离的域迁移学习

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

nodejs+npm的安装与配置

企业虚拟偶像产生了实质性的价值效益

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

IDEA02:配置SQL Server2019数据库

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

数组_滑动窗口 | leecode刷题笔记

Quickly build a website with static files

redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
随机推荐
DDTL:远距离的域迁移学习
网页三维虚拟展厅为接入元宇宙平台做基础
LDO investigation
GNSS[0]- Topic
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
JS 从零教你手写节流throttle
halcon自定义函数基本操作
Quickly build a website with static files
Promise 解决阻塞式同步,将异步变为同步
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
Flask框架初学-05-命令管理Manager及数据库的使用
GNSS文章汇总
Slipper - virtual point, shortest path
【Untitled】
观察者模式
v-model
如何通过API接口从淘宝(或天猫店)复制宝贝到拼多多接口代码对接教程
OpenCV如何实现Sobel边缘检测
【store商城项目01】环境准备以及测试
Flink jdbc connector 源码改造sink之 clickhouse多节点轮询写与性能分析