Inverts tuples from a cartesian product to a numeric index ie. the index this 
        tuple would have in a cartesian product.

        Each column gets multiplied with a place value according to the preceding columns maxmimum.

        This function in the opposite direction of utils.cartesian, ie. the last column has the highest value.

def icartesian_to_index(ranges, maxima=None):
    """
        Inverts tuples from a cartesian product to a numeric index ie. the index this 
        tuple would have in a cartesian product.

        Each column gets multiplied with a place value according to the preceding columns maxmimum.

        This function in the opposite direction of utils.cartesian, ie. the last column has the highest value.
    """
    if maxima is None:
        return reduce(lambda y,x: (x*y[1] + y[0],(np.max(x)+1)*y[1]), ranges.transpose(), (np.array([0]*ranges.shape[0]),1))[0]
    else:
        maxima_prod = np.concatenate([[1],np.cumprod(np.array(maxima))[:-1]])
        return np.sum(ranges * maxima_prod, 1)
        maxima_prod = np.concatenate([[1],np.cumprod(np.array(maxima))[:-1]])
        return np.sum(ranges[::-1] * maxima_prod, 1)