为了账号安全,请及时绑定邮箱和手机立即绑定

Python if 语句:Unndent 不匹配任何外部缩进级别

Python if 语句:Unndent 不匹配任何外部缩进级别

蓝山帝景 2022-04-23 17:21:28
我有以下 Python 代码def reward_function(params):        import math        # Read input variables        waypoints = params['waypoints']        closest_waypoints = params['closest_waypoints']        heading = params['heading']        # Initialize the reward with typical value         reward = 1.0        # Calculate the direction of the center line based on the closest waypoints        next_point = waypoints[closest_waypoints[1]]        prev_point = waypoints[closest_waypoints[0]]        # Calculate the direction in radius, arctan2(dy, dx), the result is (-pi, pi) in radians        track_direction = math.atan2(next_point[1] - prev_point[1], next_point[0] - prev_point[0])         # Convert to degree        track_direction = math.degrees(track_direction)        # Calculate the difference between the track direction and the heading direction of the car        direction_diff = abs(track_direction - heading)    if direction_diff > 180: # This line gives me the ERROR        direction_diff = 360 - direction_diff        # Penalize the reward if the difference is too large        DIRECTION_THRESHOLD = 10.0        if direction_diff > DIRECTION_THRESHOLD:        reward *= 0.5        return reward我尝试了几个不同的编辑器,但无法解决这个缩进问题。任何指针都非常受欢迎。
查看完整描述

1 回答

?
墨色风雨

TA贡献1853条经验 获得超6个赞

不要使用 8 个空格(2 个制表符),使用 4 个(1 个制表符):


def reward_function(params):

    import math

    # Read input variables

    waypoints = params['waypoints']

    closest_waypoints = params['closest_waypoints']

    heading = params['heading']

    # Initialize the reward with typical value 

    reward = 1.0

    # Calculate the direction of the center line based on the closest waypoints

    next_point = waypoints[closest_waypoints[1]]

    prev_point = waypoints[closest_waypoints[0]]

    # Calculate the direction in radius, arctan2(dy, dx), the result is (-pi, pi) in radians

    track_direction = math.atan2(next_point[1] - prev_point[1], next_point[0] - prev_point[0]) 

    # Convert to degree

    track_direction = math.degrees(track_direction)

    # Calculate the difference between the track direction and the heading direction of the car

    direction_diff = abs(track_direction - heading)

    if direction_diff > 180: # This line gives me the ERROR

        direction_diff = 360 - direction_diff

        # Penalize the reward if the difference is too large

        DIRECTION_THRESHOLD = 10.0

        if direction_diff > DIRECTION_THRESHOLD:

            reward *= 0.5

            return reward


查看完整回答
反对 回复 2022-04-23
  • 1 回答
  • 0 关注
  • 163 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信