0

I need to solve an equation, which I currently do like this:

def alpha_calculator(vals1: List[float], vals2: List[float], vals3: List[float]):
    from sympy import symbols, solve

    solutions = []
    for i, x in enumerate(vals3):
        x = symbols("x")

        alpha = vals1[i] * x + vals2[i] * (1 - x) - vals3[i]

        solution = solve(alpha)

        solutions.append(solution)

Right now this works as intended. The issue is that it is iterating through every element of each of the three lists used to solve this equation. I have never used these "solve equation" stuff before, so I don't know if there is any way to just to this on the entire length of the lists at the same time instead of iterating through every single one. It seems very inefficient, in particular if the lists are long.

Denver Dang
  • 2,433
  • 3
  • 38
  • 68

0 Answers0