in Education by
I want to multiply these two matrices using pure python. Input (M1 is 3*3 and Mt is a 3*2) M1 = [[1.0016, 0.0, -16.0514], [0.0, 10000.0, -40000.0], [-16.0514, -40000.0, 160513.6437]] Mt = [(1.0, 1.0), (0.0, 0.25), (0.0, 0.0625)] Mt is zip transpose of another matrix. My code is : def mtxmultply (X, Y): Z = [[0 for row in range(len(X))] for col in range(len(Y[0]))] for i in range(len(A)): for j in range(len(Y[0])): for k in range(len(Y)): Z[i][j] += X[i][k]*Y[k][j] return Z IndexError: list index out of range. Not getting the surety if Mt is recognised as an matrix & is still a list object. But technically this should work. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
The code should be like this for multiplication of two matrices in python- # take a 3x3 matrix C = [[1,1,1], [1,1,1], [1,1,1]] # take a 3x4 matrix D= [[2,2,2, 2], [2,2,2,2], [2,2,2,2]] R = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] # iterating by row of A for i in range(len(C)): # iterating by column by D for j in range(len(D[0])): # iterating by rows of D for k in range(len(D)): R[i][j] += C[i][k] * D[k][j] for s in result: print(s) output- [[6,6,6,6], [6,6,6,6], [6,6,6,6]]

Related questions

0 votes
    I want to test a 2x2 matrix of [[5,6],[7,8]] to see if it's a square. I run ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Forming a matrix by summing 2 arrays element-array wise using NumPy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Forming a matrix by summing 2 arrays element-array wise using NumPy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I have the 4D array, which is defined as follows: B = np.array( [[[[0.5000, 0.5625], [0.5000, ... loops and ideally one function call. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    What will be the output of the following Python function? min(max(False,-3,-4), 2,7) a) -4 b) -3 c) 2 d) False...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    I can use vi{ and va{ to select C++ code blocks. It helps me a lot when I need to yank ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    I have two list that I combine into a single list. Later I want to make a copy of this list so ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    I have an object with an attribute that is a list. For example: obj.a = [3, 4, 5] I ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I'm curious about manipulating time in Python. I can get the (last modified) age of a file using ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I have an object with an attribute that is a list. For example: obj.a = [3, 4, 5] I ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    I want to run a python script from a shell script. I have been able to run it from the "command ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    I want to run a python script from a shell script. I have been able to run it from the "command ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: asynchronous python itertools chain multiple generators (2 answers) Closed 2 ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have a variable of z storing features of length and height of image files where z is z = [ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I'm trying to make the text move continuously by pressing a button but right now it only moves an ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
...