Question: Using Python, write a program that finds the sum of two matrices This is the structure of the code R_first = len(matrix1) #number of rows

Using Python, write a program that finds the sum of two matrices

Using Python, write a program that finds the sum of two matrices

This is the structure of the code

R_first = len(matrix1) #number of rows for first matrix C_first = len(matrix1[0]) #number of columns for first matrix

inp2 = input() #reads in the second matrix inp2_strip = inp2.strip("(),[] ") #removes brackets or parantheses and spaces matrix2 = [list(map(float, t.split(","))) for t in inp2_strip.split(";")] #creates a matrix for input

'''Your Code Goes Here''' #number of rows for second matrix '''Your Code Goes Here''' #number of columns for second matrix

'''Your Code Goes Here''' #verify that the matrices are the same size matrix_sum = matrix1 for '''Your Code Goes Here''' #we need to go through each row for '''Your Code Goes Here''' #we need to go through each column '''Your Code Goes Here''' #we need to set the element of matrix_sum = to the sum of the elements from the other matrices '''Your Code Goes Here''' # we can either print the value here (don't forget to use include a space between elements) or wait and print it later print() '''Your Code Goes Here''' #if the matrices are not the right size '''Your Code Goes Here''' #print the correct statement

15.6 Matrix Addition We want to write a program that will check find the sum of two matrices. Your goal is to complete the code below to do the following: 1) Return "Undefined as the matrices are not the same size." if the matrices are not the same size. 2) Return the sum of the matrices if the matrices are the same size. Ex: If the input is: (1, 2,0;0, 0, 2) (1,2;1,2) the program would return: Undefined as the matrices are not the same size. Ex: If the input is: (1,2,0;0,0,2) (1,2,1;-1,2,0) the program would return: 2 4 1 -1 2 2 Note: The code will already be set up to accept a matrix with row entries separated by commas and rows separated by semicolons, i.e. (1,2,3,4,5,6) is the matrix 123 456 Note: The matrices are read in using list comprehension which is a compact way to do loops. It is also possible to read the matrices in using loops, loops and set comprehensions, and more depending on how you want the input to be formed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!