What will be the output of the following Python code? [code]A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]][/code] B = [[3, 3, 3],

What will be the output of the following Python code?
Code:
A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
[B[row][col]*A[row][col] for row in range(3) for col in range(3)]
A. [3, 6, 9, 16, 20, 24, 35, 40, 45]
B. Error
C. [0, 30, 60, 120, 160, 200, 300, 350, 400]
D. 0
 
Answer: a
Explanation: In the code shown above, we have used list comprehension to combine values of multiple matrices. We have multiplied the elements of the matrix B with that of the matrix A, in the range(3). Hence the output of this code is: [3, 6, 9, 16, 20, 24, 35, 40, 45].
 

Tìm kiếm

Back
Top