def multi_to_one_dim(in_shape, in_index):
    """ Convert an index from a multi-dimension into the corresponding index in flat array """
    out_index = 0
    for dim, index in zip(in_shape, in_index):
        out_index = dim * out_index + index

    return out_index