问题
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