1

Matrix Multiplication

Unsolved
Linear Algebra

Difficulty: 4 | Problem written by anish-lakkapragada
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

Matrix multiplication is extremely common in machine learning and neural networks. Write a function that takes in two 2D matrices, represented as a list of lists, and then returns the first matrix multiplied with the second. Note that matrix multiplication is not commutative. Make sure your output is a Python list of lists, where matrix[i][j] represents row i and column j of the matrix. 

Sample Input:
<class 'list'>
matrix_1: [[90, 60, 73, 43, 39, 73, 48, 94, 23, 86, 21, 65, 77], [68, 29, 70, 82, 73, 24, 17, 58, 91, 7, 14, 15, 95], [60, 23, 16, 82, 57, 51, 53, 22, 63, 82, 18, 24, 80], [91, 90, 82, 4, 53, 100, 55, 91, 5, 31, 98, 19, 100], [54, 56, 69, 4, 94, 48, 81, 57, 8, 20, 38, 32, 97], [39, 13, 6, 56, 35, 5, 44, 50, 75, 29, 54, 78, 24], [13, 15, 42, 56, 20, 29, 83, 99, 48, 86, 2, 99, 12], [75, 1, 67, 39, 17, 53, 15, 82, 9, 93, 99, 68, 88]]
<class 'list'>
matrix_2: [[14, 92, 79, 42, 2], [22, 66, 97, 65, 66], [52, 8, 85, 24, 25], [5, 68, 27, 89, 75], [3, 4, 65, 59, 46], [82, 100, 93, 30, 18], [1, 70, 97, 10, 6], [40, 15, 46, 60, 59], [94, 69, 46, 75, 99], [29, 31, 78, 71, 37], [46, 13, 17, 16, 13], [96, 98, 78, 39, 16], [39, 65, 70, 6, 90]]

Expected Output:
<class 'list'>
[[31367, 43875, 57183, 35034, 31834], [24710, 33381, 40433, 31097, 35504], [22426, 36785, 42218, 30691, 30433], [31193, 41609, 58059, 29618, 30629], [22110, 32296, 48584, 23594, 26134], [22782, 28752, 30066, 25000, 22808], [26527, 33091, 41678, 30004, 24671], [30500, 34977, 44846, 27999, 26107]]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Autem veniam pariatur, dolore sint nisi commodi aperiam, aliquam eaque magni excepturi error iusto asperiores veniam qui quidem id, dicta illo sit, quibusdam nulla sapiente nisi amet.

In tempore aspernatur, tempore beatae maxime, autem a dolorem odit temporibus culpa accusamus enim aperiam ipsa vitae error? Atque illo unde corrupti delectus commodi expedita, non placeat nihil sint porro ducimus ipsam vitae, non alias labore.

Numquam dolore repudiandae accusamus illum, labore consectetur ab fugiat voluptas ullam, molestiae quas nesciunt enim, pariatur facere architecto repellendus omnis porro unde voluptates eius? Corrupti at rem natus dicta delectus laboriosam in blanditiis ducimus maiores, officia quo quisquam at accusamus doloremque maxime amet delectus ipsa non, placeat molestias inventore quibusdam repellendus quae facere numquam consequatur autem ratione facilis, totam amet placeat, fugiat sunt a minus corporis?

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)