On Mon, 22 Feb 2021 at 15:39, Michał Pawłowski
<[email protected]> wrote:
>
> Thank you so much. But is it also possible to get formula from such array?
>
> I.e.
> getFormula("[2, 0, 2]")
> 2*x**2+2
Why is the "array" given as a string (in quotes)?
If you have a list of the coefficients then you can construct the
expression using a list comprehension:
In [1]: a = [2, 0, 1]
In [2]: x = Symbol('x')
In [3]: sum(x**n * ai for n, ai in enumerate(reversed(a)))
Out[3]:
2
2⋅x + 1
You can also use Poly:
In [4]: Poly(a, x).as_expr()
Out[4]:
2
2⋅x + 1
--
Oscar
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAHVvXxQU6SgP7Nx5YsF23_%2BUToknTydHn0NmEDuY10qLXdy9tA%40mail.gmail.com.