def choose(n, r):
    """Return number of ways of choosing r items from an array with n items.

    Parameters
    ----------
    n : int
        number of items to choose from
    r : int
        number of items to choose

    Returns
    -------
    combinations : int
        The number if ways of making the choice

    """
    if n < 0 or r < 0:
        raise ValueError('Negative values not allowed')
    if r > n:
        raise ValueError('r must not be greater than n')

    combinations = 1
    r1 = min(r, n-r)
    for k in range(r1):
        combinations = combinations * (n - k) // (k + 1)

    return combinations