import itertools


def flatten_dict(**kwargs):
    """ Flatten a dict of lists into a list of dicts
    For example
    flatten_dict(lr=[1, 2], a=[10,3], b=dict(c=[2, 4], d=np.arange(1, 3)))
    >>>
    [{'lr': 1, 'a': 10, 'b': {'c': 2, 'd': 1}},
    {'lr': 2, 'a': 3, 'b': {'c': 4, 'd': 2}}]
    """
    ks, vs = [], []
    for k, v in kwargs.items():
        ks.append(k)
        if isinstance(v, dict):
            vs.append(flatten_dict(**v))
        elif isinstance(v, (int, float)):
            vs.append([v])
        else:
            vs.append(v)

    result = []

    for k, v in itertools.product([ks], zip(*vs)):
        result.append(dict(zip(k, v)))

    return result