Please help Task1 and Task2 Do not use self
Posted: Wed Apr 27, 2022 5:07 pm
Please help Task1 and Task2
Do not use self
Task 1 • Write a function (print_matrix_info()) that will print out the following • The maximum element of the matrix • The minimum element of the matrix • The trace of the matrix • Only if the matrix is square • Otherwise, just print 'None' • Trace: the diagonal sum • The trace of the following is a + d b С d • Only defined for square matrices (same number of rows and columns) la a • Printout format: (one info per line) Max: 7 Min: -1 Trace: None
Task 2 • A transpose of a matrix is another matrix that has the original rows and columns swapped la b (d e f] [c] la d = b e Ic f • The first row becomes the first column, the n-th row becomes the n-th column • The n-th column becomes the n-th row • Write a function (transpose()) that will return the transpose of the given matrix . Try to achieve this using only a single nested for-loop
# TODO: Print the following information # Max element, Min element, Trace (only if 'm' is a square matrix) # Do not modify the following nested for-loop # Do not add other functions or loops def print_matrix_info(m): for i in range(len(m)): for j in range( len(m)): # TODO: Return the transposed matrix def transpose(m): mtx = [[2, 3, 4], [0, 0, 0], [1, 2, 3], [5, 7, -1]] print_matrix_info(mtx) # Trace should be None, Max is 7, Min is -1 print (transpose(m)) # [[2, 0, 1, 5), (3, 0, 2, 71, [4, 0, 3, -1]]
Do not use self
Task 1 • Write a function (print_matrix_info()) that will print out the following • The maximum element of the matrix • The minimum element of the matrix • The trace of the matrix • Only if the matrix is square • Otherwise, just print 'None' • Trace: the diagonal sum • The trace of the following is a + d b С d • Only defined for square matrices (same number of rows and columns) la a • Printout format: (one info per line) Max: 7 Min: -1 Trace: None
Task 2 • A transpose of a matrix is another matrix that has the original rows and columns swapped la b (d e f] [c] la d = b e Ic f • The first row becomes the first column, the n-th row becomes the n-th column • The n-th column becomes the n-th row • Write a function (transpose()) that will return the transpose of the given matrix . Try to achieve this using only a single nested for-loop
# TODO: Print the following information # Max element, Min element, Trace (only if 'm' is a square matrix) # Do not modify the following nested for-loop # Do not add other functions or loops def print_matrix_info(m): for i in range(len(m)): for j in range( len(m)): # TODO: Return the transposed matrix def transpose(m): mtx = [[2, 3, 4], [0, 0, 0], [1, 2, 3], [5, 7, -1]] print_matrix_info(mtx) # Trace should be None, Max is 7, Min is -1 print (transpose(m)) # [[2, 0, 1, 5), (3, 0, 2, 71, [4, 0, 3, -1]]