On Mon, 22 Feb 2021 at 15:39, Michał Pawłowski
<
michal.bozyd...@gmail.com> 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