Alright, thanks for the explanation.

On Mon, Mar 19, 2018 at 11:49 PM Leonid Kovalev <leonidvkova...@gmail.com>
wrote:

> lambdify should not be needed to work with or create SymPy
> expressions. Its purpose is to make a SymPy expression usable by other
> libraries.
>
> As I wrote, "dict shenanigans" were not needed. A MatrixSymbol is an
> iterable. `zip(MatrixSymbol, array_of_values)` creates an iterator of
> tuples, indicating what element is substituted by what value. A
> natural thing to do in Python, I wouldn't look to replace it with
> lambdify and DeferredVector (which apparently isn't removed because
> everyone forgot about it).
>
> On Mon, Mar 19, 2018 at 6:29 PM, Nico Schlömer <nico.schloe...@gmail.com>
> wrote:
> > I see!
> > I also noticed that I can use `DeferredVector`s instead of
> `MatrixSymbol`s
> > to get avoid those dict shenanigans. This
> > ```
> > import numpy
> > import sympy
> >
> > a = sympy.DeferredVector('a')
> > b = sympy.DeferredVector('b')
> >
> > x = sympy.Symbol('x')
> >
> > P = (a[0] + a[1]*x) / (1 + b[0]*x + b[1]*x**2 + b[2]*x**3)
> >
> > val_a = numpy.random.rand(2)
> > val_b = numpy.random.rand(3)
> >
> > Pa = sympy.lambdify((a, b), P)(val_a, val_b)
> >
> >
> > print(P)
> > print(Pa)
> > ```
> > works. It's a bit weird to create a lambdify only to call it straight
> away
> > though. Also, I'm reading [1] that `DeferredVector` were once scheduled
> for
> > removal? Probably outdated.
> >
> > [1] https://github.com/sympy/sympy/issues/6788
> >
> >
> >
> > On Monday, March 19, 2018 at 11:24:59 PM UTC+1, Leonid Kovalev wrote:
> >>
> >> P_a = P.subs(dict(zip(a, val_a)))
> >>
> >> returns
> >>
> >> (0.450033195586719*x + 0.829322314411828)/(x**3*b[2, 0] + x**2*b[1, 0] +
> >> x*b[0, 0] + 1)
> >>
> >> You need to substitute individual MatrixElement objects like a[0], not
> the
> >> MatrixSymbol itself (which isn't even present in the expression P).
> >>
> >>
> > --
> > 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 https://groups.google.com/group/sympy.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/sympy/1cdc96e2-6dd7-4540-9c55-44814d9a01b3%40googlegroups.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sympy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sympy/1A2vJdNInfE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> 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/CAJ0_tQKhWCEjB5qWvbbWaG%3D2rx6HQ-MadNZdG9AAUKRUSRG9Vw%40mail.gmail.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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAK6Z60feigN4EfDaQcQumjir9kyc0t5d%2BHoA70Jps9o915WNAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to