【发布时间】:2022-06-20 11:53:59
【问题描述】:
在 Jupyter 中,从 sympy 打印方程可能会很棘手。 IPython.display 具有显示功能,但每行仅呈现一项。 我想在同一行中显示多个项目,但在网上找不到任何可以轻松做到这一点的东西。希望这个简单的功能对其他人有所帮助
【问题讨论】:
标签: jupyter render sympy display equation
在 Jupyter 中,从 sympy 打印方程可能会很棘手。 IPython.display 具有显示功能,但每行仅呈现一项。 我想在同一行中显示多个项目,但在网上找不到任何可以轻松做到这一点的东西。希望这个简单的功能对其他人有所帮助
【问题讨论】:
标签: jupyter render sympy display equation
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])
输出:
【讨论】: