首页 > 解决方案 > 'int' 对象在我的 AI 项目中不可下标

问题描述

它在此函数的 SUM 变量中完美运行

def print_direction():
    global start_time
    stack = []
    i = end_pos[0]
    j = end_pos[1]

    SUM = int(mat[start_pos[0]][start_pos[1]]).data
    for m in range(mat_size):
        for n in range(mat_size):
            print(mat[m][n].kep, end="****")
        print()
    while i != start_pos[0] or j != start_pos[1]:
        SUM += mat[i][j].data
        stack.append(mat[i][j].direc)
        a = get_key(mat[i][j].direc)
        i -= a[0]
        j -= a[1]
    while stack:
        print(stack.pop(), end='-')
    if s == 1:
        S = "Yes"
    else:
        S = "No"
    print(" count_node: " + str(count_node) + " sum: " + str(SUM))

    ## Python program to print the data
    table = [
        ["Problem", "Heuristic name", "N", "d/N", "Success (Y/N)", "Time (sec)", "EBF", "avg H value", "Min", "Avg",
         "Max"], ["1", "straight line distance", count_node, format(deth / count_node, '.3f'), S,
                  format(time.time() - start_time, '.3f'), format(EBF / count_node, '.2f'),
                  format(E_Heuristic / time_act, '.2f'), Min, format(ave / help_ave, '.2f'), Max]]
    print(tabulate(table))
    print(help_ave)
    print(help_ave)

但不在这个变量中

temp1=int(mat[start_pos[0]][start_pos[1]]).data

标签: python

解决方案


从您发布的代码看来,正确的解决方案是:

temp1=int(mat[start_pos[0]][start_pos[1]].data)

int假设SUM += mat[i][j].data您的代码中的这一行按原样工作,则无需转换为


推荐阅读