[ create a new paste ] login | about

Link: http://codepad.org/J16EPz5J    [ raw code | output | fork ]

bpgergo - Python, pasted on Aug 25:
1
2
3
4
5
6
7
8
9
a = [[1, 2, 3], [4, 5, 6]]
b = [[1, 2], [3, 4], [5, 6]]

def mult(m1, m2):
	if len(m1[0]) != len(m2):
		raise Exception('Matrices must be m*n and n*p to multiply!')
	return map(lambda row: map(lambda col: sum(map(lambda (i,j):i*j,zip(row,col))), zip(*m2)), m1)

print mult(a, b)


Output:
1
[[22, 28], [49, 64]]


Create a new paste based on this one


Comments: