rfeynman
rfeynman

Reputation: 121

Find an easy to take out sympy results

The sympy gives out the results like:

Ellipse(Point(0,0),3,2)

Point(2.875, -0.661437827706861)

If I want to pick up these numbers: 0,0,3,2,2.875... Any simple way to get them?

Upvotes: 2

Views: 39

Answers (2)

smichr
smichr

Reputation: 19037

If you just want the numbers you can get them with atoms(Number):

>>> Point(2.875, -0.661437827706861).atoms(Number)
set([-661437827706861/1000000000000000, 23/8])
>>> Ellipse(Point(0, 0), 3, 2).atoms(Number)
set([0, 2, 3])
>>> Tuple(Point(2.875, -0.661437827706861), Ellipse(Point(0, 0), 3, 2)).atoms(
... Number)
set([0, 2, 3, -661437827706861/1000000000000000, 23/8])

Upvotes: 1

Hugh Bothwell
Hugh Bothwell

Reputation: 56644

>>> from sympy import Ellipse, Point

>>> e = Ellipse(Point(0, 0), 3, 2)

>>> p, maj, min_ = e.args

>>> maj
3

>>> p
Point(0, 0)

>>> x, y = p.args

>>> x
0

Upvotes: 2

Related Questions