def mutual_info(x, y, bins=10):
    counts_xy, bins_x, bins_y = np.histogram2d(x, y, bins=(bins, bins))
    counts_x, bins = np.histogram(x, bins=bins)
    counts_y, bins = np.histogram(y, bins=bins)

    counts_xy += 1
    counts_x += 1
    counts_y += 1
    P_xy = counts_xy / np.sum(counts_xy, dtype=float)
    P_x = counts_x / np.sum(counts_x, dtype=float)
    P_y = counts_y / np.sum(counts_y, dtype=float)

    I_xy = np.sum(P_xy * np.log2((P_x.reshape(-1, 1) * P_y) / P_xy))

    return I_xy / (entropy(counts_x) + entropy(counts_y))
dataset/ETHPy150Open luispedro/BuildingMachineLearningSystemsWithPython/ch11/demo_mi.py/mutual_info/swapped operands of `/`