gpt4 book ai didi

How to prevent Sympy printing the negative term first(如何防止Sympy先打印负项)

转载 作者:bug小助手 更新时间:2023-10-25 19:52:24 26 4
gpt4 key购买 nike



sympy prints some expressions putting the negative term first.

Sensy打印了一些表达式,将否定项放在第一位。


example:

示例:


from sympy import symbols, Matrix
import numpy as np
m = 3

obj = np.dtype(object)
ρ = np.asarray([symbols(f"ρ_{i}") for i in range(m)], obj)
ε = np.asarray([symbols(f"ε_{i}") for i in range(m)], obj)


expr = ε - ρ * ε[1]

Matrix(expr)

output:

输出:


enter image description here


Here, I want second and third elements to be printed as the first element (positive term comes first), is there a solution for that?

在这里,我希望打印第二个和第三个元素作为第一个元素(第一个元素是积极项),有什么解决方案吗?


更多回答
优秀答案推荐

The best thing you can try is:

你可以尝试的最好办法是:


from sympy import *
import numpy as np
init_printing(order="none")

then:

然后:


m = 3
obj = np.dtype(object)
ρ = np.asarray([symbols(f"ρ_{i}") for i in range(m)], obj)
ε = np.asarray([symbols(f"ε_{i}") for i in range(m)], obj)
expr = ε - ρ * ε[1]

Matrix(expr)

enter image description here


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com