Print a symbol for product (∏) by using SymPy package

别来无恙 提交于 2019-12-24 21:52:09

问题


I would like to know how to print the symbols in this picture by using SymPy package in Python.


回答1:


Symbolic products are created with Product(expr, (index, low, high)) where high is inclusive unlike in much of Python code. For example:

P00 = IndexedBase("P^{00}")
P02 = IndexedBase("P^{02}")
i = Idx("i")
t = symbols("t")
expr = Product(P00[i]*P02[t], (i, 1, t-1))
print(expr)

which prints (assuming LaTeX support) as

The placement of indices is suboptimal; the issue is that the superscripts are hardcoded into symbol names instead of being actual raised indices. But I don't see a way to tell SymPy to print certain indices as superscripts.



来源:https://stackoverflow.com/questions/52866286/print-a-symbol-for-product-%e2%88%8f-by-using-sympy-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!