回答編集履歴
2
Update
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
```python
|
2
2
|
|
3
3
|
from collections import Counter
|
4
|
+
|
5
|
+
import math
|
4
6
|
|
5
7
|
|
6
8
|
|
@@ -20,20 +22,34 @@
|
|
20
22
|
|
21
23
|
|
22
24
|
|
23
|
-
|
25
|
+
num = len(ni)
|
24
26
|
|
27
|
+
pattern = 'ACDEFGHIKLMNPQRSTVWY-'
|
28
|
+
|
25
|
-
|
29
|
+
for i in range(num):
|
30
|
+
|
31
|
+
shannon = []
|
32
|
+
|
33
|
+
for j in pattern:
|
34
|
+
|
35
|
+
pi = ni[i][j]/num
|
36
|
+
|
37
|
+
if pi > 0:
|
38
|
+
|
39
|
+
shannon.append(float(pi*math.log(pi, 2)))
|
40
|
+
|
41
|
+
print(f'{i}: {-sum(shannon)}')
|
26
42
|
|
27
43
|
|
28
44
|
|
29
45
|
#
|
30
46
|
|
31
|
-
|
47
|
+
0: -0.0
|
32
48
|
|
33
|
-
|
49
|
+
1: 0.8112781244591328
|
34
50
|
|
35
|
-
|
51
|
+
2: 1.0
|
36
52
|
|
37
|
-
|
53
|
+
3: 2.0
|
38
54
|
|
39
55
|
```
|
1
Update
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
ni =
|
19
|
+
ni = list(map(Counter, map(list, zip(*q))))
|
20
20
|
|
21
21
|
|
22
22
|
|