Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math;
- n = [15,20,35,40]
- N = 110;
- print("Извлечение 1");
- PA = [ni/N for ni in n];
- for i in range(len(PA)):
- print('Событие A'+str(i)+'- вынут шар '+str(i)+', p(A'+str(i)+')='+str(n[i])+'/'+str(N));
- HA = 0;
- for i in range(len(PA)):
- HA = HA - PA[i]*math.log2(PA[i]);
- print("HA="+str(HA));
- print("Извлечение 2");
- N = N-1;
- PAB = [];
- for i in range(len(PA)):
- pb = [];
- for j in range(len(PA)):
- nj = n[j]
- if i == j :
- nj = nj -1;
- print('PA'+str(i)+'(B'+str(j)+')='+str(nj)+'/'+str(N));
- pb.append(nj/N);
- PAB.append(pb);
- print('\n');
- HAB = 0;
- for i in range(len(PA)):
- h = 0 ;
- for j in range(len(PA)):
- h = h - PAB[i][j]*math.log2(PAB[i][j]);
- print('HA'+str(i)+'(B)='+str(h));
- HAB = HAB + h*PA[i];
- print('\n');
- print('HAB='+str(HAB)+'\n');
- print('HAB + HA='+str(HAB+HA));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement