8. Calculate sum of diagonals of matrix using Python

preview_player
Показать описание
Hello Learners!!
In this video, we are going to learn how to calculate the sum of diagonals of a matrix using Python
We will solve this using two approaches:
1 Using the Nested list
2. Using NumPy Library
Timeline:
00:00 Introduction
02:24 Calculating the sum of primary diagonal elements using nested lists
07:02 Calculating the sum of secondary diagonal elements using nested lists (Approach 1)
11:56 Calculating the sum of secondary diagonal elements using nested lists (Approach 2)
16:57 Calculating the sum of diagonal elements using NumPy
---------------------------------------------------------------------------------------------------------------------

If you haven't checked my previous videos as yet,
Watch my videos on Python to learn in the easiest way possible
Follow the full playlist from here:
1. Python Basics:
2. Python Patterns:
3.Python Programs:

Follow my blog for notes:

------------------------------------------------------------------------------------------------------------------

Related Tags:
sum of diagonal of matrix
sum of diagonal matrix in python
calculate the sum of diagonals in a matrix
sum of diagonal elements of a matrix python
sum of diagonal elements of a matrix python numpy
sum of diagonal elements of a matrix is called
sum the diagonal of a matrix python
sum of diagonal elements matrix
sum diagonal matrix numpy
sum of diagonal elements of a matrix numpy
sum of diagonal of matrix in python
sum of diagonal elements of a matrix python without numpy
sum of diagonal elements of a matrix
sum of diagonal elements of matrix
find the sum of diagonal elements of a matrix
sum of diagonal elements in 2d array
sum of diagonal of a 3x3 matrix
code for sum of diagonal elements in matrix
how to find the sum of diagonal elements of a matrix
Рекомендации по теме
Комментарии
Автор

Thanks for such a nice and comprehensive solution. Keep helping. Really appreciate.

prachisaxena
Автор

Thanx to your wonderful efforts. This is easiest way, love you so much and effort. Keep it up

MoneyAndProfit
Автор

Thank you for this content! The only video that made me understand this topic
Love your accent

suddenly
Автор

# Sum of secondary principal diagonal elements of a matrix

A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
n=4
for i in range(len(A)): # Corrected
for j in range(len(A[i])): # Corrected
if ((i+j) == (n-1)):
print(A[i][j])
sum = 0
for i in range(len(A)):
for j in range(len(A[i])):
if ((i+j) == (n-1)):
sum = sum + A[i][j]
print("sum:", sum)



Output: 6
8



What is the wrong with this code mam, output coming is incorrect



Please reply madam

rachankumar
Автор

ma'am, I have one doubt, for an odd square matrix how to find the sum of all diagonal matrix without repetition of any element

ajeetshahu
Автор

Mam, clearly understood ....Thanq so much mam for ur efforts fr me mam...U will have a nice future in this platform I think so...As a viewer, my advice is that try to avoid mistakes mam...It may increasing the time ...Viewers also expect the shortest video...

gayathri--is
Автор

ans, n = 0, len(a)
for i in range(len(a)):
ans += a[i][i]
ans += a[i][n-1-i]
return ans-(a[n//2][n//2] if n%2 else 0)

mariomathew
Автор

Mam, can I expect some more videos ..Bcoz I was searching but I didnt get the clear understanding of the program

gayathri--is
Автор

Respected mam,
Instead of taking j = n-i-1, can we take i+j = len(matrix)?
would it work ?

alokik
Автор

it is impossible to listen to... even if it contains a good explanation, sorry.

elenagavrilova
visit shbcf.ru