Example #1
0
 def test_multiply(self):
     self.assertEqual(multiply.multiply(
         [[1, 2, 3], [2, 1, 1]], [[1], [2], [3]]), [[14], [7]])
Example #2
0
 def test_multiply(self):
     self.assertEqual(multiply.multiply(
         [[1, 2, 3], [2, 1, 1]], [[1], [2], [3]]), [[14], [7]])
"""
This algorithm takes two compatible two dimensional matrix
and return their product
Space complexity: O(n^2)
Possible edge case: the number of columns of multiplicand not consistent with
the number of rows of multiplier, will raise exception
"""

###two compatible two dimensional matrix

from algorithms.matrix.multiply import multiply

alist = [[3, 4], [3, 4]]
blist = [[1, 2], [3, 4]]

print(multiply(alist, blist))