python - '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
解决方案
从您发布的代码看来,正确的解决方案是:
temp1=int(mat[start_pos[0]][start_pos[1]].data)
int
假设SUM += mat[i][j].data
您的代码中的这一行按原样工作,则无需转换为
推荐阅读
- wpf - 禁用“拖动时显示窗口内容”时,拖动的窗口位置值不会在 WPF 中更新
- react-native - 如何在反应导航4中显示标签栏图标
- vtiger - vtiger crm 7中的引导vtlib脚本是什么?
- javascript - 如何从JS中的对象中获取数组
- python - Python删除由数据框列组成的列表列表中的外引号
- python - 最大序列长度对 Grover 的影响
- three.js - 如何通过鼠标选择矩形选择对象?
- javascript - 如果选项卡自动重新加载,浏览器扩展“browser.tabs.onUpdated.addListener”适用于 Chrome,但不适用于 Firefox
- css - Css Grid 媒体查询元素被推到外面
- c++ - 如何编写递归多数元素算法