TypeError:'NoneType'对象不可迭代从初学者2开始

时间:2018-05-19 23:12:10

标签: python-3.6

我有一个代码和错误消息说 [Q_table, pre_s, pre_a, s, a]= select_action(x,x_dot,theta,theta_dot,R, Q_table, pre_s, s, pre_a, a, alpha, beta, gamma) TypeError:' NoneType '对象不可迭代

基本上我试图在其他地方调用此函数: 在我之前的帖子中,我在另一个代码上有类似的问题,我的错误是缺少的返回语句,但现在,我有一个返回的政治家,我不能理解这个问题。请帮我。谢谢你们:)

[Q_table, pre_s, pre_a, s, a]= select_action(x,x_dot,theta,theta_dot,R, Q_table, pre_s, s, pre_a, a, alpha, beta, gamma)


def select_action(x,x_dot,theta,theta_dot,R,Q_table,pre_s,s,pre_a,a,alpha,beta,gamma):
pre_s = s
pre_a = a
s = select_box(x, x_dot, theta, theta_dot)


if (pre_a != -1):    # Update Q value. If previous action been taken
   if (s == -1):        # Current state is failed
      predicted_value = 0        # fail state's value is zero
   elif (Q_table[s, 0] <= Q_table[s, 1]):        # Left Q<= Right Q
        predicted_value = Q_table[s, 1]        #  set Q to bigger one
   else:
        predicted_value = Q_table[s, 1]

        Q_table[pre_s, pre_a] = Q_table[pre_s, pre_a] + alpha * (R + gamma * predicted_value - Q_table[pre_s, pre_a])

       # Determine best action
b=beta*random()
if ((Q_table[s, 0] + b <= Q_table[s, 1]).all()):
    a = 2            # push right
else:
    a = 1
    return [Q_table, pre_s, pre_a, s, a]

1 个答案:

答案 0 :(得分:0)

明确两个&#39;

[Q_table, pre_s, pre_a, s, a]= select_action(x,x_dot,theta,theta_dot,R, Q_table, pre_s, s, pre_a, a, alpha, beta, gamma)


def select_action(x,x_dot,theta,theta_dot,R,Q_table,pre_s,s,pre_a,a,alpha,beta,gamma):
    pre_s = s
    pre_a = a
    s_another = select_box(x, x_dot, theta, theta_dot)


    if (pre_a != -1):    # Update Q value. If previous action been taken
       if (s_another == -1):        # Current state is failed
          predicted_value = 0        # fail state's value is zero
       else:
          if (Q_table[s_another, 0] <= Q_table[s_another, 1]):        # Left Q<= Right Q
            predicted_value = Q_table[s_another, 1]        #  set Q to bigger one
          else:
            predicted_value = Q_table[s_another, 0]

            Q_table[pre_s, pre_a] = Q_table[pre_s, pre_a] + alpha * (R + gamma * predicted_value - Q_table[pre_s, pre_a])

        # Determine best action
        b=beta*random()
        if ((Q_table[s_another, 0] + b <= Q_table[s_another, 1]).all()):
            a = 2            # push right
        else:
            a = 1
    return [Q_table, pre_s, pre_a, s_another, a]