from itertools import chain, combinations

def group(n, iterable):
    s = list(iterable)
return [c for c in chain.from_iterable(combinations(s, r) for r in range(
    len(s) + 1)) if sum(c) == n]
Numpy - group data into sum values