How to best return a function with dynamic variable names? Usually one should avoid it. But due to external package constraints this might not always be possible. E.g. LMFit uses explicit variable names to adress parameters of the model.
If the function is
def (x, y):
return y*x
then one needs to adress the parameter by its explcit name y
.
For complex, generic fitting models one might need to dynamically generate a model with different parameters e.g.:
def make_model(x, myDict):
...
def myModel(x, V1, V2):
...
...
return result
return myModel
In this example I want to change the names of the variables V1
and V2
to e.g. the keys of myDict
. Is this possible? Should one do this at all and if not, how else do I create a function with exchangable variable names for use in such packages?
I do not want to keep them to be called V1
and V2
because when adressing them later (and when having > 5 parameters) it might be clumsy to keep track of the names for the user.