Search code examples
pythonmatlabnumpyinline

Matlab's Inline function in Python


In Matlab, we can do

x = -10:.1:10;
f = inline('normpdf(x,3,2) + normpdf(x,-5,1)','x');
t = plot(x,f(x))

Do we have a similar function like inline in Python?


Solution

  • I think the python equivalent of "Inline" would be lambda

     Matlab:
     f = inline('normpdf(x,3,2) + normpdf(x,-5,1)','x');
    
     python:
     f = lambda x : normpdf(x,3,2) + normpdf(x,-5,1)
     # Assuming that normpdf is defined and in scope ;-)