I’m finding difficulting what exactly the doctest in the following code is looking for in the function.
Can someone make it more clear for me, please?
- Write functions row_times_column and matrix_mult:
def row_times_column(m1, row, m2, column):
"""
>>> row_times_column([[1, 2], [3, 4]], 0, [[5, 6], [7, 8]], 0)
19
>>> row_times_column([[1, 2], [3, 4]], 0, [[5, 6], [7, 8]], 1)
22
>>> row_times_column([[1, 2], [3, 4]], 1, [[5, 6], [7, 8]], 0)
43
>>> row_times_column([[1, 2], [3, 4]], 1, [[5, 6], [7, 8]], 1)
50
"""
def matrix_mult(m1, m2):
"""
>>> matrix_mult([[1, 2], [3, 4]], [[5, 6], [7, 8]])
[[19, 22], [43, 50]]
>>> matrix_mult([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 1], [2, 3]])
[[31, 19], [85, 55]]
>>> matrix_mult([[7, 8], [9, 1], [2, 3]], [[1, 2, 3], [4, 5, 6]])
[[39, 54, 69], [13, 23, 33], [14, 19, 24]]
"""
Add your new functions to matrices.py and be sure it passes the
doctests above.
Its asking you to implement some matrix multiplication methods.
In the first one, given a matrix, multiply the row of m1 x the column of m2. The first one given is:
but we only want row 0 times col 0, so it would be
= 5+14 = 19. And so on for the others…
The second function wants a full matrix multiplication. See http://en.wikipedia.org/wiki/Matrix_multiplication