Question

Write a Python function called sumNxN with three parameters. The first parameter is a nested list...

Write a Python function called sumNxN with three parameters. The first parameter is a nested list (matrix) representing a matrix of size N x N. The second parameter is the integer N, and the third is a list of N zeros.

Modify the list of zeros so that each entry is the sum of the corresponding column. There is no return.

Note: You may assume the sizes provided are all correct.

Homework Answers

Answer #1

Solution:

The code is written in python3.

Code of the function sumNxN:

def sumNxN(matrix,N,L):
    for i in range(0,N):
        sum = 0
        for j in range(0,N):
            #Sum of a column
            sum += matrix[j][i]
        L[i] = sum

Code with implementation:

def sumNxN(matrix,N,L):
    for i in range(0,N):
        sum = 0
        for j in range(0,N):
            #Sum of a column
            sum += matrix[j][i]
        L[i] = sum

#for testing
matrix=[[1,2,3,4],
        [0,2,3,4],
        [4,3,2,1],
        [3,3,3,3]]
N=4
L=[0,0,0,0]

sumNxN(matrix,N,L)
print(L)

Screenshot of Code and output :

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python function count_bigger that takes two parameters, a nested list of objects and a...
Write a Python function count_bigger that takes two parameters, a nested list of objects and a threshold number. It returns an integer specifying how many of the objects anywhere in the nested list are numbers that are larger than the threshold. (For our purposes, "numbers" are either integers or floats.) There may be objects in the list other than numbers, in which case you would simply ignore them. Here are a couple of examples of how the function should behave...
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
Use the Design Recipe to write a function count_evens_NxN,  that consumes a nested list representing a matrix...
Use the Design Recipe to write a function count_evens_NxN,  that consumes a nested list representing a matrix of size NxN. The function should return the number of even numbers in the matrix. For this function, 0 is considered an even number.  Include a Docstring! Note: You may assume the list argument passed to the function is a nested list of integers. Write 3 assert_equal statements to test your function.
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
Hello! I am confused on the code for this question. Write a complete Python function called...
Hello! I am confused on the code for this question. Write a complete Python function called Frog, with two integer parameters M and N, where N has the default value of 5. The function computes and returns one of two results: if N is odd it returns the equation 2 * M + N, but if it is even it returns the equation 3 * M - N instead.
• First, create a function called addNumber, which has a formal parameter for an array of...
• First, create a function called addNumber, which has a formal parameter for an array of integers and increase the value of each array element by a random integer number between 1 to 10. o Add any other formal parameters that are needed. • Second, create another function called printReverse that prints this array in reverse order. • Then, you need to write a C++ program to test the use of these two functions.
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an n-by-n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note that...
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a...
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a new array of that many double's initializes all elements to be 0 returns this array
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT