def entropy(X, Y):
    probs = []
for c1 in set(X):
    for c2 in set(Y):
        probs.append(np.mean(np.logical_and(X == c1, Y == c2)))
return np.sum(-p * np.log2(p) for p in probs if p > 0)
Энтропия Шеннона к взаимной информации