-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixGenerator.py
More file actions
52 lines (38 loc) · 1.08 KB
/
MatrixGenerator.py
File metadata and controls
52 lines (38 loc) · 1.08 KB
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
#!/usr/bin/python
#coding=utf-8
import sys
import argparse
import time
import random
progress_step = 5
parser = argparse.ArgumentParser()
parser.add_argument('size', help='matrix size', type=int)
args = parser.parse_args()
n = args.size
if len(sys.argv) != 2:
print 'Wrong argument. Usage {0}.py size'.format(sys.argv[0])
f_matrix = open('matrix.txt', 'w')
f_vector = open('vector.txt', 'w')
f_vector.write('{0}\r\n'.format(str(n)))
f_matrix.write('{0}\r\n'.format(str(n)))
maximum = n * n
line = [0] * n
print 'Start generation'
prev_progress = 0
current_progress = 0
t0 = time.clock()
for i in xrange(n):
for j in xrange(n):
if j == i:
line[j] = 1.0
else:
line[j] = random.uniform(0, n) / maximum
f_matrix.write(' '.join(str(x) for x in line))
if i != n - 1:
f_matrix.write('\r\n')
f_vector.write('{0} '.format(str(sum(line))))
current_progress = int(i * 100.0 / n)
if current_progress >= prev_progress + progress_step :
print '{0}%'.format(current_progress)
prev_progress = current_progress
print 'Generation completed! In: {0} second'.format(time.clock() - t0)