-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab02.py
More file actions
57 lines (43 loc) · 1.12 KB
/
lab02.py
File metadata and controls
57 lines (43 loc) · 1.12 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
53
54
55
56
57
import math
f = open("toeprint.rdat")
c = [a.split("\t") for a in f.readlines()]
# delete unnecessary text
for i in range(len(c)):
del c[i][0:3]
# delete \n
for i in range(len(c) - 1):
c[i][len(c[0]) - 1] = c[0][len(c[i]) - 1].rstrip()
for i in range(len(c)):
c[i] = (list(map(int, c[i])))
sums = [sum(c[0]), sum(c[1])]
# a)
norm = []
for i in range(len(c)):
norm.append([])
for j in range(len(c[i])):
norm[i].append(round((c[i][j] * 1000000) / sums[i], 4))
# b)
norm2 = []
avgs = [sum(c[0]) / len(c[0]), sum(c[1]) / len(c[1])]
for i in range(len(c)):
norm2.append([])
for j in range(len(c[i])):
if c[i][j] != 0:
norm2[i].append(round(math.log(c[i][j] / avgs[i], 2), 4))
# task 2
#first normalization:
result = []
for i in range(len(norm[0])):
try:
result.append(norm[0][i] / norm[1][i])
except:
result.append(0)
print(result.index(max(result)) + 1)
#second normalization:
result = []
for i in range(len(norm2[0])):
try:
result.append(norm2[0][i] - norm2[1][i])
except:
result.append(0)
print(result.index(max(result)) + 1)