All problems
Reward Scaling by Maximum Absolute Value
Problem
Normalize a list of rewards by dividing by the largest absolute reward.
An empty list returns []. If every reward is zero, return a list of zeros instead of dividing by zero.
Hint
Scaling by the maximum magnitude keeps signs and bounds every value in [-1, 1].
Test cases
case 1
in: [[1,-2,4]]
expected: [0.25,-0.5,1]
case 2
in: [[]]
expected: []
case 3
in: [[0,0]]
expected: [0,0]
case 4
in: [[-3,-6]]
expected: [-0.5,-1]
Starter codePython
def normalize_rewards(rewards):
# Your code here
pass4 test cases · run your code against them in the editor