Modules do not send or something like that. The way lambdify works is that it creates
lambda x: exp(x)
where exp comes from the namespace of the modules (modules) that you have selected. lambdify(x, exp(x), ['numpy', 'sympy']) roughly equivalent
from sympy import * from numpy import *
If you want to provide a custom function that sends messages, you can use something like the example of Saullo Castro. You can also use this with lambdify by providing a dict like
import numpy as np import sympy def myexp(x): if isinstance(x, np.ndarray): return np.exp(x) else: return sympy.exp(x) func = lambdify(x, exp(x), [{'exp': myexp}, 'numpy'])
This gives
>>> func(np.array([1, 2])) array([ 2.71828183, 7.3890561 ]) >>> func(sympy.Symbol('y')) exp(y)
source share