Search code examples
pythonsympylambdify

sympy lambdify: how to make more functions (NCDF, NPDF, etc) available


How do I make sympy’s lambdify accept more function names, like a Normal function, for example? To make something like this work:

lambdify(('x',), 'NPDF(x, 0, 1)')

I don’t mind using the Normal function from the sympy statistics module, as long as it doesn’t create a new Normal() distribution object every time the lambda gets called.


Solution

  • If you have a numerical implementation of the function you want to use, pass it in the second argument, like

    lambdify(x, NPDF(x, 0, 1), modules=['numpy', {'NPDF': NPDF_implementation}])