[Python] How to multiply the elements of an array to the corresponding elements of a set of...

Discussão em 'Python' iniciado por Stack, Janeiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    How do I multiply the elements of an array to the corresponding elements of a set of DataFrames? My matrices are quite large, but for the sake of simplicity I will use only a 2x3 dimension:

    For example, if given the following array and set of DataFrames:

    Array A:
    [ [1 2 1]
    [1 3 2] ]


    Set of 2 DataFrames B:
    3 1 2
    1 0 1

    2 0 3
    4 2 0


    I would like to multiply each element of Matrix A to each corresponding element of the DataFrames in Set B. Doing so should yield the following result (set of 2 DataFrames):


    Resulting Set:


    3 2 2
    1 0 2

    2 0 3
    4 6 0


    Ideally, I need to keep the result in the form of two separate DataFrames for the analysis to follow.

    I have been able to get the algebraic result, but only in the form of one condensed 4x3 array (ie, the two 2x3 matrices combined into one 4x3, leaving me unable to apply it for the next step of analysis). I am sure I am overlooking something simple and straight forward. Let me know if you have any suggestions – Very appreciative :).

    Continue reading...

Compartilhe esta Página