import math


def bucket_size(array, ndivs=None, low=None, width=None):
    """Determine the bucket size needed to divide the values in array into
       'ndivs' evenly sized buckets"""

    if low is None:
        low = min(array)

    if ndivs is None:
        if width is None:
            ndivs = 20
        else:
            ndivs = int(math.ceil(max((max(array) - low) / float(width), 1)))

    if width is None:
        width = (max(array) - low) / float(ndivs)

    return ndivs, low, width