[Python] The best way to reduce the calculation time of formulas in nested loops?

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    Could you tell me what is the best way to reduce the calculation time of formulas in nested loops? I have code like this:

    for k in range(0, 130):
    for i in range(0, 1600):
    array2[i,k] = 0
    for j in range(0, 1600):
    array2[i,k] = array2[i,k] + constant_value * (array1[j,k] * function1(i - j))


    Array1 and array2 contain double numbers. This block of code executes in 15-20 minutes. The problem is that the block is nested in another loop that has 100 to 400 iterations, so sometimes it takes more than 24 hours to calculate. Is there a way to speed up this piece of code?

    Continue reading...

Compartilhe esta Página