-
Notifications
You must be signed in to change notification settings - Fork 56
/
psyco-ikj-multiplication.py
executable file
·53 lines (41 loc) · 1.04 KB
/
psyco-ikj-multiplication.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# Core Library modules
from optparse import OptionParser
# First party modules
import psyco
psyco.full()
def read(filename):
lines = open(filename).read().splitlines()
A = []
B = []
matrix = A
for line in lines:
if line != "":
matrix.append(map(int, line.split("\t")))
else:
matrix = B
return A, B
def print_matrix(matrix):
for line in matrix:
print("\t".join(map(str, line)))
def ikj_matrix_product(A, B):
n = len(A)
C = [[0 for i in xrange(n)] for j in xrange(n)]
for i in xrange(n):
for k in xrange(n):
for j in xrange(n):
C[i][j] += A[i][k] * B[k][j]
return C
if __name__ == "__main__":
parser = OptionParser()
parser.add_option(
"-i",
dest="filename",
default="2000.in",
help="input file with two matrices",
metavar="FILE",
)
(options, args) = parser.parse_args()
A, B = read(options.filename)
C = ikj_matrix_product(A, B)
print_matrix(C)