[Python] Simplify expected value expression in Simpy

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

  1. Stack

    Stack Membro Participativo

    Is there a way to simplify an equation with expected values without explicitly calculating them? For example, let X, Y be two dependent random variables. My equation is:

    from sympy.stats import E

    E(X + E(X*Y) + 2*X - Y)


    The answer I would like to obtain is:

    3*E(X) + E(X*Y) - E(Y)


    If I define the variables (for example as standard normal) I just get an exact value, and on the other hand, if I define X and Y as symbols, the equation will be simplify using E(X) = X, , which is of course not correct.

    I believe the answer is simple, but I am new to SymPy and would be grateful for any help.

    Continue reading...

Compartilhe esta Página