Question
use Python IDEL
Problem 4 Fix a program. This program should calculate the matrix addition (C - A+B, where each element of matrix C is equal
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#order of the matrix
m,n = 3,3
A = [[1,0,0],
[0,1,0],
[0,0,1]]
B = [[2,0,0],
[2,0,0],
[2,0,0]]
#matrix C
C = []
#we will add all the columns rowwise
for i in range(m):
#appending an empty list
C.append([])
#initializing that list
C[i] = [0]*3
#adding the element at i,j and storing it in C at i,j
for j in range(n):
C[i][j] = A[i][j] + B[i][j]
#printing each row at a time
print(C[i])

_______________________________________________

CODE IMAGES AND OUTPUT:

________________________________________-

Feel free to ask any questions in the comments section

Thank You!

Add a comment
Know the answer?
Add Answer to:
use Python IDEL Problem 4 Fix a program. This program should calculate the matrix addition (C...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be in Python(please have a screen shot on these solution code) 11.5 (Algebra: add two...

    Must be in Python(please have a screen shot on these solution code) 11.5 (Algebra: add two matrices) Write a function to add two matrices. The header of the function is def addMatrix(a, b): In order to be added, the two matrices must have the same dimensions and the same or compatible types of elements. Let c be the resulting matrix. Each element Cij is aij + bij. For example, for two 3 X 3 matrices a and b, c is...

  • Please code in MatLab or Octave Output should match Sample Output in the second picture Thank...

    Please code in MatLab or Octave Output should match Sample Output in the second picture Thank You 4. In this problem we will investigate using loops to calculate the product of two matrices. Given an mxn matrix A and an n x p matrix B, the matrix product C = AB is the m xp matrix with Cij = R=1 Qikbky. Write a program which calls a function get matrix.dimensions which should • print a description of the purpose of...

  • Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_RO...

    Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS = 10; const int MAX_COLS = 10; class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand);...

  • The following C++  code contains an incomplete program that should be able to calculate the distance between...

    The following C++  code contains an incomplete program that should be able to calculate the distance between a series of geocoded locations. Two parts of the program need to be completed: 1. The portion of the main() function that calculates the distances between each of the hard-coded 5 locations, and stores it in a two-dimensional array declared as distances. 2. A portion of the calculateDistanceBetweenLocations(l1, l2) function; omitted code spaces are designed with a // TODO: comment. The code is properly...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT