Answer: here is the answer for your code:
code:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
def Sum_Of_Diagonal (a,dim):
#variables to store sum of diagonals and initialized to 0
Sum_Of_Diagonal1 = 0
Sum_Of_Diagonal2 = 0
for rows in range(0, dim):
for columns in range(0, dim):
if (rows == columns):# condition for Diagonal1
Sum_Of_Diagonal1 = Sum_Of_Diagonal1+a[rows][columns]
if ((rows + columns) == (dim - 1)):# condtion for
Diagonal2
Sum_Of_Diagonal2 = Sum_Of_Diagonal1+a[rows][columns]
print ("sum of 1st Diagonal:", Sum_Of_Diagonal1)
print ("sum of 2nd Diagonal:",Sum_Of_Diagonal2)
a =[[9, 13, 5, 2],
[1, 11, 7, 6],
[3, 7, 4, 1],
[6,0, 7, 10]]
Sum_Of_Diagonal (a,4)#calling function
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT:

I hope this would help you out
If you have any doubt, you can provide comment /feedback below the answer
Thanks
Write the code in python 5. (10 points) Write a function that takes a square matrix...
QUESTION 5: Write a C++ function called layers which takes an NxN integer array (for some constant N) and populates the entries 0..N2-1 as follows: The upper left entry (row-0, col-0) is 0. Subsequent numbers are assigned along Southwest-to-Northeast diagonals, layer-by-layer. For example, if N=4, your function would result in the following assignment to entries in the array: 0 2 5 9 1 4 8 12 3 7 11 14 6 10 13 15 (the individual “layers” are shown by...
1. Write a MATLAB function that takes a matrix, a row number and
a scalar as
arguments and multiplies each element of the row of the matrix by
the scalar returning the
updated matrix.
2. Write a MATLAB function that takes a matrix, two row numbers and
a scalar as
arguments and returns a matrix with a linear combination of the
rows. For example, if the rows
passed to the function were i and j and the scalar was m,...
How to solve it using Python?
5. Write a function called no_squares which takes an input parameter N, a positive integer, and returns: 1 if N is not divisible by a square and has an even number of prime factors -1 if N is not divisible by a square and has an odd number of prime factors 0 if N is divisible by a square For example, no-squares (10) returns 1 (since 10 = 2x5), no-squares (30) returns-1 (since 30...
This is a python work, thank for helping!
7. (6 points) Write a function, countOfAndSmalest Number Between(low, high, ignore, listOfNumbers), that takes as input three numbers and a list of numbers, and returns a list containing two items: 1) how many items in listOfNumbers are greater than low, less than high, and not equal to ignore 2) the smallest number in listOfNumbers that is greater than low, less than high, and not equal to ignore (or None if there is...
Python
1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...
Please, write a function in PYTHON without NumPy that diagonalizes a square matrix
Matlab code
4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...
The
question is attached in following two photos. Please use Matlab if
you exactly know how to do it. Thank you.
Linorm.m Create a function Linorm which takes one argument, M a square matrix and computes the LI-norm of the matrix. This is a number associated to each square matrix M, denoted lIMll, as follows. For each column of the matrix we add together the absolute values of the entries in that column, and we then take the maximum of...
FOR PYTHON: Write a function findMinRow() that
takes a two-dimensional list of numbers as a parameter. It
returns the index of the minimum row in the list.
The minimum row is the row with the smallest sum of elements. If
the list has multiple rows that achieve the minimum value, the last
such row should be returned. If the list is empty the function
should return -1. The following shows several sample runs of the
function:
Python 3.4.1 Shell File...
In Python beginner code: Write a function named even_div, that takes two arguments (you can safely assume that both arguments will always be non-zero integers). When this function is called, it should return how many times the first argument can be divided by the second argument, if it is evenly divisible (no remainder). If it is not evenly divisible, the function should return 0. Examples: even_div(5, 2) will return 0 (5 divided by 2 is 2.5, not evenly divisible) even_div(10,...