ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 02 Oct 2019 23:56:06 +0200Extraction of a result in an other formhttps://ask.sagemath.org/question/48151/extraction-of-a-result-in-an-other-form/For the following code
pol = Polyhedron(ieqs = [[5, -1/2, -1/4],[-18, 1, 3],[0, 1, 0], [0, 0, 1]])
vr=pol.Vrepresentation()
vr
the result is
(A vertex at (0, 20), A vertex at (42/5, 16/5), A vertex at (0, 6))
How to have it as
pol= [(0, 20),(42/5, 16/5),(0, 6)] ?
Wed, 02 Oct 2019 23:36:04 +0200https://ask.sagemath.org/question/48151/extraction-of-a-result-in-an-other-form/Answer by tmonteil for <p>For the following code </p>
<pre><code>pol = Polyhedron(ieqs = [[5, -1/2, -1/4],[-18, 1, 3],[0, 1, 0], [0, 0, 1]])
vr=pol.Vrepresentation()
vr
</code></pre>
<p>the result is</p>
<pre><code>(A vertex at (0, 20), A vertex at (42/5, 16/5), A vertex at (0, 6))
</code></pre>
<p>How to have it as</p>
<p>pol= [(0, 20),(42/5, 16/5),(0, 6)] ?</p>
https://ask.sagemath.org/question/48151/extraction-of-a-result-in-an-other-form/?answer=48152#post-id-48152As you can see, the returned elements are vertices, with their own methods, like the ability to provide its neighbors in the polyhedron.
sage: v = vr[0]
sage: v
A vertex at (0, 20)
sage: type(v)
<class 'sage.geometry.polyhedron.representation.Vertex'>
You can transform a vertex into a tuple as follows:
sage: tuple(v)
(0, 20)
So, to do that for each element of the list, you can just use list comprehension:
sage: [tuple(v) for v in vr]
[(0, 20), (42/5, 16/5), (0, 6)]
Wed, 02 Oct 2019 23:56:06 +0200https://ask.sagemath.org/question/48151/extraction-of-a-result-in-an-other-form/?answer=48152#post-id-48152