Sachin_ruk - 1 year ago 51

Python Question

I need to obtain a list of functions, where my function is defined as follows:

`import theano.tensor as tt`

def tilted_loss(y,f,q):

e = (y-f)

return q*tt.sum(e)-tt.sum(e[e<0])

I attempted to do

`qs = np.arange(0.05,1,0.05)`

q_loss_f = [tilted_loss(q=q) for q in qs]

however, get the error

`TypeError: tilted_loss() missing 2 required positional arguments: 'y' and 'f'`

`a = tilted_loss(q=0.05)`

How do you go about creating this list of functions when parameters are required? Similar questions on SO consider the case where parameters are not involved.

Answer Source

You can use `functools.partial`

:

```
q_loss_f = [functools.partial(tilted_loss, q=q) for q in qs]
```