I am trying to use the argmax function of numpy to take two argument. Here is the code:
UP = 1
DOWN = 2
LEFT = 3
RIGHT = 4
actlist = [UP, DOWN, LEFT, RIGHT]
a = numpy.argmax(actlist, lambda a: expected_utility(a,i,j,U))
The problem is, one of the arguments is the return value of a function. It returns an integer.
The function expected_utility(a,i,j,U)
looks like:
def expected_utility(a,i,j,U):
return sum(p*U[i][j] for (k,l,p) in T(i,j,a))
If I use lambda with the second parameter of the argmax
function, I am getting an error:
TypeError: 'function' object cannot be interpreted as an integer
If I don't use lambda with the second parameter of the argmax
function, I am getting the error:
UnboundLocalError: local variable 'a' referenced before assignment
I am using Python 3.6.5
Now I am even confused with how argmax
function even works. What is the role of lambda here.