Created
April 25, 2011 13:52
-
-
Save brentp/940537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import array | |
# Writen by Attractive Chaos; distributed under the MIT license | |
# reference: http://www.syntagmatic.net/matrix-multiplication-in-python/ | |
def matmul(a, b): # FIXME: no error checking | |
ra, rb = list(range(len(a))), list(range(len(b))) | |
c = [array.array('d', [b[j][i] for j in rb]) for i in rb] | |
d = [array.array('d', [0 for j in range(len(b[0]))]) for i in ra] # transpose | |
for i in ra: | |
ai = a[i] | |
for j in rb: | |
d[i][j] = sum(ai[k] * c[j][k] for k in ra) | |
return d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import array | |
# Writen by Attractive Chaos; distributed under the MIT license | |
# reference: http://www.syntagmatic.net/matrix-multiplication-in-python/ | |
def matmul(a, b): # FIXME: no error checking | |
ra, rb = list(range(len(a))), list(range(len(b))) | |
c = [array.array('d', [b[j][i] for j in rb]) for i in rb] | |
d = [array.array('d', [0 for j in range(len(b[0]))]) for i in ra] # transpose | |
for i in ra: | |
ai = a[i] | |
for j in rb: | |
d[i][j] = sum(ai[k] * c[j][k] for k in ra) | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment