Trouble using lambdify

63 views
Skip to first unread message

Eduardo Rivera

unread,
Nov 27, 2016, 8:00:27 PM11/27/16
to sympy
Hi, I need help, I'm trying to use lambdify to use scipy solvers, however I can't seem to be able to convert it into a solvable array of numpy functions(it was an array of sympy expressions), this leads to a bunch of non callable errors. It does work if I just call it: f(x1,x2,x3) with known values though

test=lambdify((la1,la2,la3,la4,la5),steadystate)
x0
=np.array([0.5,0.5,0.5,.5,.5])
print(test(1,1,1,1,1)) #works
print(test(x0)) # throws error
res=opt.root(test, x0) #also doesn't work


I think Im doing something wrong but not sure why, and I really need the scipy solvers.

Denis Akhiyarov

unread,
Dec 5, 2016, 4:13:19 AM12/5/16
to sympy
You need to unpack your x0 with * syntax.

So test(*x0).

Aaron Meurer

unread,
Dec 5, 2016, 2:04:29 PM12/5/16
to sy...@googlegroups.com
If you need lambdify to take a single argument, which unpacks to the
variables, you can pass a nested tuple, like

lambdify(((la1, la2, la3, la4, la5),), steadystate)
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@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/5cb09590-b9ec-4374-b561-2ef5f217d98e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Eduardo Rivera

unread,
Dec 5, 2016, 6:39:13 PM12/5/16
to sympy
Thank you both, I fixed it by using a "wrapper" function that yielded the tuples, and to make it work I needed the "unpack" tip from Denis. Next time I try the nested tuples solution, I had no idea that could be done!

Regards
Reply all
Reply to author
Forward
0 new messages