Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Each individual list will represent a row. For instance [[1,1,1],[2,2,2],[3,3,3]

ID: 3598189 • Letter: E

Question

Each individual list will represent a row. For instance [[1,1,1],[2,2,2],[3,3,3]] represents a matrix with all entries in the i th row being equal to i.

Using Python, Write a function matMul, which accepts two arguments. When being called as matMul(A,B) with matrices A, B the function must

-return the matrix product A*B, if isMatrix(A) and isMatrix(B) are both True and the number of columns in A is equal to the number of rows in B;

-otherwise the function must return a string "invalid arguments"

*Please go step by step and can you please explain why for each step*

Explanation / Answer

import sys

data=sys.stdin.readlines()

#3x3 matrix

x=[[1,1,1],

[2,2,2],

[3,3,3]]

#3x3 matrix

y=[[1,1,1],

[2,2,2],

[3,3,3]];

result is 3x3

result=[[0,0,0],

[0,0,0],

[0,0,0]]

#iterate through rows of x

for i in range(len(x)):

#iterate through column of y

for i in range(len y[0])):

#iterate through rows of y

for k in range (len(y)):

result [i][j]+=x[i][k]*y[k][j]

for r in result:

print(r)

elif

st="invalid arguments"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote