def take_product(do_dict):
'''
this function takes some dictionary like:
{key1:1, key2:[a,b], key3:[c,d]}
and returns the dictionary:
{key1:[1,1,1], key2[a,a,b,b,],key3[c,d,c,d]}
computing the product of values
'''
values=[]
for v in do_dict.values():
if hasattr(v,'__iter__'):
values.append(v)
else:
values.append([v])#allows scalar to be passed
prod_values=np.vstack(product(*values))
return {k:np.array(v) for k,v in zip(do_dict.keys(),zip(*prod_values))}
评论列表
文章目录