-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrandom_weight.py
32 lines (27 loc) · 972 Bytes
/
random_weight.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
import random
def random_weights(dim):
weights = [[0 for _ in range(dim)] for _ in range(dim)]
for i in range(dim):
for j in range(dim):
if i < j:
continue
if i == j:
weights[i][j] = 0
else:
if random.random() > 0.5:
weights[i][j] = random.randint(1, 15)
weights[j][i] = weights[i][j]
else:
weights[i][j] = 1000000
weights[j][i] = 1000000
return weights
def pretty_matrix(matrix):
s = [[str(e) for e in row] for row in matrix]
lens = [max(map(len, col)) for col in zip(*s)]
fmt = '\t'.join('{{:{}}}'.format(x) + ',' for x in lens)
table = ['[ ' + fmt.format(*row) + ' ],' for row in s]
print '\n'.join(table)
if __name__ == "__main__":
# for weight in random_weights(10):
# print str(weight) + ','
pretty_matrix(random_weights(10))