Python 如何在列表中查找数组的索引

Python 如何在列表中查找数组的索引,python,numpy,Python,Numpy,假设您有一个数组列表。然后分别指定一个也出现在列表中的。你如何得到它的索引 In [185]: y_train.index(Y_test[0]) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-185-c9

假设您有一个数组列表。然后分别指定一个也出现在列表中的。你如何得到它的索引

In [185]: y_train.index(Y_test[0])
 ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-185-c9084f698632> in <module>()
 ----> 1 y_train.index(Y_test[0])
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
这里,y_train是包含所有内容的“大”列表,y_test[0]是其中的一个元素

for i in range(0, len(y_train)):
 for j in range(0, len(Y_test)):
     if y_train[i].shape==Y_test[j].shape:
        v= y_train[i]==Y_test[j]
        if v.all():
           print ('i',i)
           print ('j',j)

这可以找到我要查找的索引。错误源于这样一个事实,即当模糊地处理多个元素的数组时,不清楚真值应该是什么

而不是口头解释counts\u train和X\u test包含什么,显示示例数据如何存储在这些变量中的实际代码将更好地澄清您的问题。