好吧,在我的Python代码中,我试图用一个列表打印出一个列表列表的索引,如下所示:
print(datos.tolist().index(lista_muestra_pequena[1]))
“datos”和“lista\u muestra\u pequena”是两个列表列表,我想知道哪个索引在“datos”中有lista_muestra_pequena[1]
。
“datos”实际上是一个numpy数组,这就是为什么我把.tolist()
执行Python时出现一个错误,这个错误:
print(datos.tolist().index(lista_muestra_pequena[1]))
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我理解函数“a.all()”,用于数组,指定数组的所有元素是否必须满足条件,或者在“a.any()”情况下仅满足一个条件。不过,我不明白你为什么要告诉我这个案子。我试着把np.全部()“在两个网站上线,但我不明白。你知道吗
.index()
方法将不使用数组作为参数(假设lista_muestra_pequena
是数组)。你知道吗要获取
datos
的索引(其中lista_muestra_pequena[1]
),可以使用numpy.where()方法:相关问题 更多 >
编程相关推荐