考虑以下代码:
for record in training_data_list:
all_values = record.split(',')
A = A[int(all_values[0])]
执行时出现以下错误:
IndexError:标量变量的索引无效。
如何防止此错误? A的形状为(10,103),A的内容为:
A=[[ 0.54791709 0.54943806 0.55004389 ..., 0.55054129 0.55054109
0.55054601]
[ 0.45400955 0.45505433 0.45480845 ..., 0.4555305 0.45553331
0.45553635]
[ 0.66672558 0.66327062 0.66624759 ..., 0.66594688 0.6659449
0.6659411 ]
...,
[ 0.69362838 0.693958 0.69394086 ..., 0.69512919 0.69512934
0.69512978]
[ 0.44799209 0.45074033 0.44861442 ..., 0.44922826 0.44923215
0.44923314]
[ 0.46524247 0.46462676 0.46453131 ..., 0.46502923 0.46502886
0.46502859]]
为了澄清一点,当all_values [0] = 0时,我需要A的第一条记录, 当all_values [0] = 1时,我需要A的第二条记录,...,当all_values [0] = 9时,我需要A的第十条记录!