import math


def calculate_entropy(data):
    """Calculates the entropy for a given array"""
    unique_values = list(set(data))
    data_length = len(data)
    entropy = 0
    for value in unique_values:
        count = data.count(value)
        # entropy with the sum formula, with reversed log because of the -
        entropy += (count / data_length) * math.log2(data_length / count)
    return entropy