Ask Your Question
4

How can the independent variable be extracted from a SymPy Poly?

asked 2023-05-08 12:46:06 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-08 13:03:01 +0000

nofretete gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2023-05-08 12:46:06 +0000

Seen: 10 times

Last updated: May 08 '23