Lambda’s take the same signature as regular functions, and you can give reg
a default:
f = lambda X, model, reg=1e3: cost(X, model, reg=reg, sparse=np.random.rand(10,10))
What default you give it depends on what default the cost
function has assigned to that same parameter. These defaults are stored on that function in the cost.__defaults__
structure, matching the argument names. It is perhaps easiest to use the inspect.getargspec()
function to introspect that info:
from inspect import getargspec
spec = getargspec(cost)
cost_defaults = dict(zip(spec.args[-len(defaults:], spec.defaults))
f = lambda X, model, reg=cost_defaults['reg']: cost(X, model, reg=reg, sparse=np.random.rand(10,10))
Alternatively, you could just pass on any extra keyword argument:
f = lambda X, model, **kw: cost(X, model, sparse=np.random.rand(10,10), **kw)