【问题标题】:Render multiple equations symbols side by side in Jupyter在 Jupyter 中并排渲染多个方程符号
【发布时间】:2022-06-20 11:53:59
【问题描述】:

在 Jupyter 中,从 sympy 打印方程可能会很棘手。 IPython.display 具有显示功能,但每行仅呈现一项。 我想在同一行中显示多个项目,但在网上找不到任何可以轻松做到这一点的东西。希望这个简单的功能对其他人有所帮助

【问题讨论】:

    标签: jupyter render sympy display equation


    【解决方案1】:
    from IPython.display import display, Markdown
    from sympy import Matrix, I, latex
    
    def printmult(lst):
        output = ""
        for l in lst:
            if isinstance(l, str):
                output += f"{l}"
            else:
                output += f"${{{latex(l)}}}$ "
    
        display(Markdown(output))
    
    
    Xm = Matrix([[0,1],[1,0]])
    Ym = Matrix([[0,-I],[I,0]])
    
    K1 = Matrix([[0],[1]])
    
    res = Xm*Ym*K1
    print("Each renders on a different line")
    display (Xm, Ym, K1, " = ", res)
    
    print("All render on the same line")
    printmult([Xm, Ym, K1, " = ", res])
    

    输出:

    【讨论】:

      猜你喜欢
      • 2016-06-17
      • 2020-02-28
      • 2023-02-20
      • 2017-09-22
      • 2017-10-15
      • 2019-04-30
      • 1970-01-01
      • 2019-12-18
      • 2011-01-23
      相关资源
      最近更新 更多