AndrewDAG
AndrewDAG

Reputation: 65

Need help converting a math formula in Python code

i have this formula over here:

enter image description here

I've been working on this for the last 6 hours and can't get a coded version down in Python. Could someone with some math skills help me out in this task?

Thank you very much,

Edit: This is my current attempt:

def create_group(i, k):
    return (my_list[i] - my_list[i - k]) * my_other_list[i - k]

def computation():
        
    main = []
    new_group_container = []

    for i in range(len(my_list)):
        for k in range(len(main)):
            new_group = create_group(i=i, k=k)
            new_group_container.append(new_group)
        group = sum(new_group_container) 
        main.append(group)

    return main

Upvotes: 1

Views: 167

Answers (1)

AndrewDAG
AndrewDAG

Reputation: 65

SOLUTION (Thank you @RobertDodier):

rows = [x for x in range(len(X))]
cols = [x for x in range(len(X))]
matrix = [[0 for i in range(len(X))] for j in range(len(X))]
for i in rows:
    for k in cols:
        term = (X[i] - X[i - k]) * Y[i - k]
        matrix[i][k] = term
        if k >= i:
             break
 main = []
 for e in matrix:
     o = sum(e)
     main.append(o)

Upvotes: 1

Related Questions