簡體   English   中英

在Sympy中將x / 2打印為1/2 x

[英]Print x/2 as 1/2 x in Sympy

我如何告訴Sympy將x / 2打印為1/2 x? 即在分母上乘分子的分數等於1?

我相信,要正確執行此操作,您將必須編寫自己的打印機。 若要駭人聽聞,您可以嘗試:

mul = x/2
a, b = mul.as_two_terms()
if a.is_Rational and not a.is_Integer:
    print (Mul(Symbol(str(a.p))/a.q, b, evaluate=False))
else:
    print (mul)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM