# 根据索引列表对输入的数值列表进行重排序
# 例如索引列表index=[0,2,1,3] value_list=[12,23,144,233] ————> result=[12,144,23,233]
# 例如索引列表index=[[0],[2,1,3]] value_list=[12,23,144,233] ————> result=[[12],[144,23,233]]
# 例如索引列表index=[[[0],[[2,1],[3]]]] value_list=[12,23,144,233] ————> result=[[[12],[[144,23],[233]]]]
# index=[[0],[2,1],[3]]
# index=[0,2,1,3]
# index=[[[0],[[2,1],[3]]]]
# value_list=[12,23,144,233]
index=[[[3]],[[0,1],[2]]]
value_list=[0,3,1,5]
result=index
for i in range (0,len(index)):
if isinstance(index[i],list):
for j in range(0,len(index[i])):
if isinstance(index[i][j],list):
for k in range(0,len(index[i][j])):
if isinstance(index[i][j][k],list):
for m in range(0,len(index[i][j][k])):
result[i][j][k][m]=value_list[result[i][j][k][m]]
else:
result[i][j][k]=value_list[result[i][j][k]]
else:
result[i][j]=value_list[result[i][j]]
else:
result[i]=value_list[index[i]]
print(result)
将其转换至Mech-Vision中,添加【使用Python计算结果】step:
注意数据维度:
注意传参,尤其是数据维度:
其中resorted_by_index.py程序需要放在该工程的根目录下,加入参数后代码如下:
def output(index,value):
result=index
for i in range (0,len(index)):
if isinstance(index[i],list):
for j in range(0,len(index[i])):
if isinstance(index[i][j],list):
for k in range(0,len(index[i][j])):
if isinstance(index[i][j][k],list):
for m in range(0,len(index[i][j][k])):
result[i][j][k][m]=value[result[i][j][k][m]]
else:
result[i][j][k]=value[result[i][j][k]]
else:
result[i][j]=value[result[i][j]]
else:
result[i]=value[index[i]]
return result