def pearsonchisquare(counts):
    """
    Calculate Pearson's χ² (chi square) test for an array of bytes.

    See [http://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test
    #Discrete_uniform_distribution]

    Arguments:
        counts: Numpy array of counts.

    Returns:
        χ² value
    """
    np = sum(counts) / 256
    return sum((counts - np)**2 / np)