To extract the independent variable from a SymPy Poly object, you can use the gens
attribute. The gens
attribute returns a tuple of the generator symbols of the Poly. The independent variable is typically the first generator symbol in the tuple.
For example, consider the following SymPy Poly object:
from sympy import Poly, symbols
x, y = symbols('x y')
p = Poly(x**2 + 2*x*y**2, x, y)
To extract the independent variable from p
, you can use the gens
attribute as follows:
independent_variable = p.gens[0]
print(independent_variable) # Output: x
Note that the gens
attribute returns a tuple, so you can access the generator symbols by their index in the tuple. In this case, since x
is the first generator symbol, we access it with index 0.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-08 12:46:06 +0000
Seen: 10 times
Last updated: May 08 '23
"How can a Boolean variable be saved in SQFLite?"
Can I assign a variable within destructuring assignment using 'let' and then reassign it later?
How can I transfer variables to a pipeline variable?
Is it not possible to store the sum using getBoundingClientRect into a variable?
Is it possible to monitor the variable's real-time value in CLion?