以下是一个示例1 item在我的清单中:
array([[ 1, 2, 3,
43, 83, 92],
[ 12, 54, 93,
23, 94, 83],
[ 23, inf, inf,
inf, inf, inf],
[ 83, 33, 33,
83, 13, 83],
[ 83, nan, 83,
73, 43, 43],
[ 43, 83, 93,
22, 83, 54],
[ 66, nan, 74,
84, 84, 75],
[ 74, 44, 65,
6, 9, 7],
[ 54, 9, 74,
754, 55, 74]])
其中一些项目包含inf
or nan
价值观。因此,我试图返回包含此类值的项目的索引。因此我尝试执行以下操作:
for x in f:
if float('inf') in x:
idx.append(f.index(x))
elif float('nan') in x:
idx.append(f.index(x))
但是,当我运行脚本时,出现以下错误:
idx.append(f.index(x))
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
这是为什么?我该如何解决这个问题?
As a reminder,以上样本仅1 item。由于它包含inf
and nan
,我想返回该项目的索引。该项目基本上是列表的列表。
Thanks.