I would first generate the list of monomial indices by using e.g. 
itertool.product, then create a dictionary containing the indexed 
coefficients, and finally create a Poly object with given variables from 
those coefficients. For example, to construct a polynomial of degree 3 or 
less in 3 variables this could be done:

indices = [i for i in itertools.product(range(4), repeat=3) if sum(i) < 4]
a = IndexBase('a')
coeffs = {i: a[i] for i in indices}
vars = symbols('x:3')
Poly(coeffs, *vars)

Kalevi Suominen

On Wednesday, August 1, 2018 at 2:01:13 PM UTC+3, foadsf wrote:
>
> I want to use power series to approximate some PDEs. The first step I need 
> to generate symbolic multivariate polynomials, given a numpy ndarray.
>
> Consider the polynomial below:
>
> <https://i.stack.imgur.com/eBQVK.png>
>
>
> I want to take a m dimensional ndarray of D=[d1,...,dm] where djs are 
> non-negative integers, and generate a symbolic multivariate polynomial in 
> the form of symbolic expression. The symbolic expression consists of 
> monomials of the form:
>
> <https://i.stack.imgur.com/pvDDT.png>
>
>
> Fo example if D=[2,3] the output should be
>
> <https://i.stack.imgur.com/nDhGD.png>
>
>
> For this specific case I could nest two for loops and add the 
> expressions. But I don't know what to do for Ds with arbitrary length. If 
> I could generate the D dimensional ndarrays of A and X without using for 
> loops, then I could use np.sum(np.multiply(A,X)) as Frobenius inner 
> product <https://en.wikipedia.org/wiki/Frobenius_inner_product> to get 
> what I need.
>
> I would appreciate if you could help me know how to do this in SymPy. 
> Thanks in advance.
>

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/1c70ac48-9c09-43b5-9374-15acb37d2860%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to