def greedyPolicy(Ts, R, discountFactor, V):
 dim = len(V)
 numA = len(Ts)
 Vnext = ((V * discountFactor) + R)
 policy = zeros((dim, numA))
 for si in range(dim):
  actions = all_argmax([dot(T[si, :], Vnext) for T in Ts])
  for a in actions:
   policy[(si, a)] = (1.0 / len(actions))
 return (policy, collapsedTransitions(Ts, policy))

def greedyPolicy ( Ts , R , discountFactor , V ) : dim = len ( V ) numA = len ( Ts ) Vnext = ( ( V * discountFactor ) + R ) policy = zeros ( ( dim , numA ) ) for si in range ( dim ) : actions = all_argmax ( [ dot ( T [ si , : ] , Vnext ) for T in Ts ] ) for a in actions : policy [ ( si , a ) ] = ( 1.0 / len ( actions ) ) return ( policy , collapsedTransitions ( Ts , policy ) )
find the greedy policy .