Search code examples
pythonexcelnp

Python np.convolve/SUMPRODUCT for many Arrays


I need to implement this formula Excel in Python

SUMPRODUCT($C$10:D$10;$C$30:D$30;reverse($C$40:D$40);reverse($C$50:D$50))

I trying this with np.convolve, But this function accept only two array.

Any ideas please?


Solution

  • a = np.array([1,2,3])
    b = np.array([4,5,6])
    c = np.array([7,8,9])
    d = np.array([10,11,12])
    
    sumproduct = np.sum(a*b*c*d)
    

    You can reverse arrays using np.flip(array,axis).