[Python] Sum up column values by special logic

Discussão em 'Python' iniciado por Stack, Julho 9, 2025.

  1. Stack

    Stack Membro Participativo

    Say we have an array like:

    a = np.array([
    [k11, k12, k13, k14, k15, k16, k17, k18],
    [k21, k22, k23, k24, k25, k26, k27, k28],
    [k31, k32, k33, k34, k35, k36, k37, k38],
    [k41, k42, k43, k44, k45, k46, k47, k48]
    ])

    const = C


    I need to create a vector from this array like this (runge kutta 4):

    result = np.array([
    const * (k11 + 2*k21 + 2*k31 + k41),
    const * (k12 + 2*k22 + 2*k32 + k42),
    const * (k13 + 2*k23 + 2*k33 + k43),
    ....
    const * (k18 + 2*k28 + 2*k38 + k48)
    ])


    I am able to do this in cycle, but I am pretty sure numpy methods allow this in vectorised form.

    Continue reading...

Compartilhe esta Página