It looks like Poly.from_dict will do it:

In [6]: p = Poly(6*x**4*y**5 + 3*x*y**2,y,x)

In [7]: p.as_dict()
Out[7]: {(2, 1): 3, (5, 4): 6}

In [8]: p.from_dict(p.as_dict(), y, x)
Out[8]: Poly(6*y**5*x**4 + 3*y**2*x, y, x, domain='ZZ')

The order of the generators is the same as the order in the Poly. I
don't remember if there is a better method on Poly for reordering
generators, but in the above example Poly(p, x, y) will reorder them.

Aaron Meurer


On Fri, Mar 27, 2015 at 2:50 PM, Paul Royik <distantjob...@gmail.com> wrote:
> Suppose I have following polynomial:
> poly= Poly(6*x**4*y**5 + 3*x*y**2,y,x)
>
> It's dictionary is
> poly.as_dict() # {(5, 4): 6, (2, 1): 3}
>
>
> How can I restore poly from dict?
> How do I know that (5, 4) - > (y, x) ?
> poly.free_symbols is set, so it is unordered.
>
> Is there any way to fetch that from Poly?
>
> One way I think is following:
>
> variables = [x,y]
> poly= Poly(6*x**4*y**5 + 3*x*y**2,variables)
>
> #(5, 4) - > variables
>
>
> And next question: how are coeffcients are ordered? Can I change order?
> order keyword throws exception...
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/b03e1f10-6b62-4725-ab01-a142b26d8a06%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6KE6So5r_Swn%3D%3D%3DnmQ_SFB_VQMc3J8TesnHAy2MWhQ1tQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to