[Solved] How to get sum of products of all combinations in an array in Python? [closed]


You can do with numpy and itertools:

from numpy import linspace, prod
from itertools import combinations

arr = np.array([1,2,3,4])

[sum([prod(x) for x in combinations(arr,int(i))]) for i in linspace(1,len(arr), len(arr))]
[10, 35, 50, 24]

solved How to get sum of products of all combinations in an array in Python? [closed]