Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

What are the determinants of cash cycle ? Explain

Answered: 1 week ago