1

Can someone explain to me my why this is an invalid syntax? It comes in the line before the last line.

import random

class BernoulliArm():

    def __init__(self, p):
         self.p=p

    def draw(self):
        if random.random()>self.p:
            return 0.0
        else:
            return 1.0

means = [0.1, 0.1, 0.1, 0.1, 0.9]
n_arms = len(means)
random.shuffle(means)    

arms = map(lambda (mu):BernoulliArm(mu), means)    
arms[0].draw()
0

1 Answer 1

2

In Python, lambda does not use parentheses around the parameter names:

arms = map(lambda mu: BernoulliArm(mu), means)    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.