All problems
Policy Extraction From Q
Problem
Extract a greedy policy from an action-value table.
For each state row return the index of the largest Q value, breaking ties by choosing the smallest action index. An empty Q table returns an empty list.
Hint
Use a strict greater-than comparison so the earliest maximum wins ties.
Test cases
case 1
in: [[[1,3,2],[5,5,1]]]
expected: [1,0]
case 2
in: [[[0,-1],[-2,-3]]]
expected: [0,0]
case 3
in: [[[7]]]
expected: [0]
case 4
in: [[]]
expected: []
Starter codePython
def policy_from_q(Q):
# Your code here
pass4 test cases · run your code against them in the editor