I\'m trying to write a function that adds two matrices to pass the following doctests:
>>> a = [[1, 2], [3, 4]] >>> b = [[2, 2], [2, 2]
from itertools import izip def add_matrices(c, d): return [[a+b for a, b in izip(row1, row2)] for row1, row2 in izip(c, d)]
But as said above, there is no need to reinvent the wheel, just use numpy, which is likely to be faster and more flexible.
numpy