forked from MartinThoma/matrix-multiplication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createMatrix.py
30 lines (26 loc) · 827 Bytes
/
createMatrix.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import random
random.seed(1234)
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-n", dest="n", type="int", default=2000,
help="How big should the two matrices be?")
(options, args) = parser.parse_args()
def createRandomMatrix(n):
maxVal = 1000 # I don't want to get Java / C++ into trouble ;-)
matrix = []
for i in xrange(n):
matrix.append([random.randint(0, maxVal) for el in xrange(n)])
return matrix
def saveMatrix(matrixA, matrixB, filename):
f = open(filename, 'w')
for i, matrix in enumerate([matrixA, matrixB]):
if i != 0:
f.write("\n")
for line in matrix:
f.write("\t".join(map(str, line)) + "\n")
n = options.n
matrixA = createRandomMatrix(n)
matrixB = createRandomMatrix(n)
saveMatrix(matrixA, matrixB, str(n) + ".in")